@ -9,7 +9,7 @@
* @ license BSL - 1.0 License ( https : //opensource.org/license/bsl1-0-html)
*
* Copyright ( c ) 2003 - 2013 Christopher M . Kohlhoff
* Copyright ( C ) 2023 Bryan Biedenkapp , N2PLL
* Copyright ( C ) 2023 , 2024 Bryan Biedenkapp , N2PLL
*
*/
# if !defined(__REST_HTTP__SERVER_CONNECTION_H__)
@ -93,27 +93,32 @@ namespace network
HTTPLexer : : ResultType result ;
char * content ;
std : : tie ( result , content ) = m_lexer . parse ( m_request , m_buffer . data ( ) , m_buffer . data ( ) + bytes_transferred ) ;
// catch exceptions here so we don't blatently crash the system
try
{
std : : tie ( result , content ) = m_lexer . parse ( m_request , m_buffer . data ( ) , m_buffer . data ( ) + bytes_transferred ) ;
std : : string contentLength = m_request . headers . find ( " Content-Length " ) ;
if ( contentLength ! = " " ) {
size_t length = ( size_t ) : : strtoul ( contentLength . c_str ( ) , NULL , 10 ) ;
m_request . content = std : : string ( content , length ) ;
}
std : : string contentLength = m_request . headers . find ( " Content-Length " ) ;
if ( contentLength ! = " " ) {
size_t length = ( size_t ) : : strtoul ( contentLength . c_str ( ) , NULL , 10 ) ;
m_request . content = std : : string ( content , length ) ;
}
m_request . headers . add ( " RemoteHost " , m_socket . remote_endpoint ( ) . address ( ) . to_string ( ) ) ;
m_request . headers . add ( " RemoteHost " , m_socket . remote_endpoint ( ) . address ( ) . to_string ( ) ) ;
if ( result = = HTTPLexer : : GOOD ) {
m_requestHandler . handleRequest ( m_request , m_reply ) ;
write ( ) ;
}
else if ( result = = HTTPLexer : : BAD ) {
m_reply = HTTPPayload : : statusPayload ( HTTPPayload : : BAD_REQUEST ) ;
write ( ) ;
}
else {
read ( ) ;
if ( result = = HTTPLexer : : GOOD ) {
m_requestHandler . handleRequest ( m_request , m_reply ) ;
write ( ) ;
}
else if ( result = = HTTPLexer : : BAD ) {
m_reply = HTTPPayload : : statusPayload ( HTTPPayload : : BAD_REQUEST ) ;
write ( ) ;
}
else {
read ( ) ;
}
}
catch ( const std : : exception & e ) { : : LogError ( LOG_REST , " ServerConnection::read(), %s " , ec . message ( ) . c_str ( ) ) ; }
}
else if ( ec ! = asio : : error : : operation_aborted ) {
if ( ec ) {
@ -151,7 +156,7 @@ namespace network
asio : : error_code ignored_ec ;
m_socket . shutdown ( asio : : ip : : tcp : : socket : : shutdown_both , ignored_ec ) ;
}
catch ( const std : : exception & e ) { : : LogError ( LOG_REST , " %s" , ec . message ( ) . c_str ( ) ) ; }
catch ( const std : : exception & e ) { : : LogError ( LOG_REST , " ServerConnection::write(), %s" , ec . message ( ) . c_str ( ) ) ; }
}
if ( ec ! = asio : : error : : operation_aborted ) {