@ -393,16 +393,6 @@ bool ClientAllowed(const boost::asio::ip::address& address)
@@ -393,16 +393,6 @@ bool ClientAllowed(const boost::asio::ip::address& address)
return false ;
}
class AcceptedConnection
{
public :
virtual ~ AcceptedConnection ( ) { }
virtual std : : iostream & stream ( ) = 0 ;
virtual std : : string peer_address_to_string ( ) const = 0 ;
virtual void close ( ) = 0 ;
} ;
template < typename Protocol >
class AcceptedConnectionImpl : public AcceptedConnection
{
@ -819,33 +809,18 @@ static string JSONRPCExecBatch(const Array& vReq)
@@ -819,33 +809,18 @@ static string JSONRPCExecBatch(const Array& vReq)
return write_string ( Value ( ret ) , false ) + " \n " ;
}
void ServiceConnection ( AcceptedConnection * conn )
static bool HTTPReq_JSONRPC ( AcceptedConnection * conn ,
string & strRequest ,
map < string , string > & mapHeaders ,
bool fRun )
{
bool fRun = true ;
while ( fRun & & ! ShutdownRequested ( ) )
{
int nProto = 0 ;
map < string , string > mapHeaders ;
string strRequest , strMethod , strURI ;
// Read HTTP request line
if ( ! ReadHTTPRequestLine ( conn - > stream ( ) , nProto , strMethod , strURI ) )
break ;
// Read HTTP message headers and body
ReadHTTPMessage ( conn - > stream ( ) , mapHeaders , strRequest , nProto ) ;
if ( strURI ! = " / " ) {
conn - > stream ( ) < < HTTPReply ( HTTP_NOT_FOUND , " " , false ) < < std : : flush ;
break ;
}
// Check authorization
if ( mapHeaders . count ( " authorization " ) = = 0 )
{
conn - > stream ( ) < < HTTPReply ( HTTP_UNAUTHORIZED , " " , false ) < < std : : flush ;
break ;
return false ;
}
if ( ! HTTPAuthorized ( mapHeaders ) )
{
LogPrintf ( " ThreadRPCServer incorrect password attempt from %s \n " , conn - > peer_address_to_string ( ) ) ;
@ -856,10 +831,8 @@ void ServiceConnection(AcceptedConnection *conn)
@@ -856,10 +831,8 @@ void ServiceConnection(AcceptedConnection *conn)
MilliSleep ( 250 ) ;
conn - > stream ( ) < < HTTPReply ( HTTP_UNAUTHORIZED , " " , false ) < < std : : flush ;
break ;
return false ;
}
if ( mapHeaders [ " connection " ] = = " close " )
fRun = false ;
JSONRequest jreq ;
try
@ -891,11 +864,43 @@ void ServiceConnection(AcceptedConnection *conn)
@@ -891,11 +864,43 @@ void ServiceConnection(AcceptedConnection *conn)
catch ( Object & objError )
{
ErrorReply ( conn - > stream ( ) , objError , jreq . id ) ;
break ;
return false ;
}
catch ( std : : exception & e )
{
ErrorReply ( conn - > stream ( ) , JSONRPCError ( RPC_PARSE_ERROR , e . what ( ) ) , jreq . id ) ;
return false ;
}
return true ;
}
void ServiceConnection ( AcceptedConnection * conn )
{
bool fRun = true ;
while ( fRun & & ! ShutdownRequested ( ) )
{
int nProto = 0 ;
map < string , string > mapHeaders ;
string strRequest , strMethod , strURI ;
// Read HTTP request line
if ( ! ReadHTTPRequestLine ( conn - > stream ( ) , nProto , strMethod , strURI ) )
break ;
// Read HTTP message headers and body
ReadHTTPMessage ( conn - > stream ( ) , mapHeaders , strRequest , nProto ) ;
// HTTP Keep-Alive is false; close connection immediately
if ( mapHeaders [ " connection " ] = = " close " )
fRun = false ;
if ( strURI = = " / " ) {
if ( ! HTTPReq_JSONRPC ( conn , strRequest , mapHeaders , fRun ) )
break ;
}
else {
conn - > stream ( ) < < HTTPReply ( HTTP_NOT_FOUND , " " , false ) < < std : : flush ;
break ;
}
}