@ -54,7 +54,8 @@ static string rfc1123Time()
return DateTimeStrFormat ( " %a, %d %b %Y %H:%M:%S +0000 " , GetTime ( ) ) ;
return DateTimeStrFormat ( " %a, %d %b %Y %H:%M:%S +0000 " , GetTime ( ) ) ;
}
}
string HTTPReply ( int nStatus , const string & strMsg , bool keepalive )
string HTTPReply ( int nStatus , const string & strMsg , bool keepalive ,
bool headersOnly , const char * contentType )
{
{
if ( nStatus = = HTTP_UNAUTHORIZED )
if ( nStatus = = HTTP_UNAUTHORIZED )
return strprintf ( " HTTP/1.0 401 Authorization Required \r \n "
return strprintf ( " HTTP/1.0 401 Authorization Required \r \n "
@ -73,6 +74,7 @@ string HTTPReply(int nStatus, const string& strMsg, bool keepalive)
" </HEAD> \r \n "
" </HEAD> \r \n "
" <BODY><H1>401 Unauthorized.</H1></BODY> \r \n "
" <BODY><H1>401 Unauthorized.</H1></BODY> \r \n "
" </HTML> \r \n " , rfc1123Time ( ) , FormatFullVersion ( ) ) ;
" </HTML> \r \n " , rfc1123Time ( ) , FormatFullVersion ( ) ) ;
const char * cStatus ;
const char * cStatus ;
if ( nStatus = = HTTP_OK ) cStatus = " OK " ;
if ( nStatus = = HTTP_OK ) cStatus = " OK " ;
else if ( nStatus = = HTTP_BAD_REQUEST ) cStatus = " Bad Request " ;
else if ( nStatus = = HTTP_BAD_REQUEST ) cStatus = " Bad Request " ;
@ -80,12 +82,19 @@ string HTTPReply(int nStatus, const string& strMsg, bool keepalive)
else if ( nStatus = = HTTP_NOT_FOUND ) cStatus = " Not Found " ;
else if ( nStatus = = HTTP_NOT_FOUND ) cStatus = " Not Found " ;
else if ( nStatus = = HTTP_INTERNAL_SERVER_ERROR ) cStatus = " Internal Server Error " ;
else if ( nStatus = = HTTP_INTERNAL_SERVER_ERROR ) cStatus = " Internal Server Error " ;
else cStatus = " " ;
else cStatus = " " ;
bool useInternalContent = false ;
if ( nStatus ! = HTTP_OK ) {
contentType = " text/plain " ;
useInternalContent = true ;
}
return strprintf (
return strprintf (
" HTTP/1.1 %d %s \r \n "
" HTTP/1.1 %d %s \r \n "
" Date: %s \r \n "
" Date: %s \r \n "
" Connection: %s \r \n "
" Connection: %s \r \n "
" Content-Length: %u \r \n "
" Content-Length: %u \r \n "
" Content-Type: application/json \r \n "
" Content-Type: %s \r \n "
" Server: bitcoin-json-rpc/%s \r \n "
" Server: bitcoin-json-rpc/%s \r \n "
" \r \n "
" \r \n "
" %s " ,
" %s " ,
@ -94,8 +103,10 @@ string HTTPReply(int nStatus, const string& strMsg, bool keepalive)
rfc1123Time ( ) ,
rfc1123Time ( ) ,
keepalive ? " keep-alive " : " close " ,
keepalive ? " keep-alive " : " close " ,
strMsg . size ( ) ,
strMsg . size ( ) ,
contentType ,
FormatFullVersion ( ) ,
FormatFullVersion ( ) ,
strMsg ) ;
headersOnly ? " " :
useInternalContent ? cStatus : strMsg . c_str ( ) ) ;
}
}
bool ReadHTTPRequestLine ( std : : basic_istream < char > & stream , int & proto ,
bool ReadHTTPRequestLine ( std : : basic_istream < char > & stream , int & proto ,