@@ -12,7 +12,6 @@ HTTPConnection::HTTPConnection(ResourceResolver * resResolver):
1212
1313 _connectionState = STATE_UNDEFINED;
1414 _clientState = CSTATE_UNDEFINED;
15- _httpHeaders = NULL ;
1615 _defaultHeaders = NULL ;
1716 _isKeepAlive = false ;
1817 _lastTransmissionTS = millis ();
@@ -40,7 +39,7 @@ int HTTPConnection::initialize(int serverSocketID, HTTPHeaders *defaultHeaders)
4039 if (_socket >= 0 ) {
4140 HTTPS_LOGI (" New connection. Socket FID=%d" , _socket);
4241 _connectionState = STATE_INITIAL;
43- _httpHeaders = new HTTPHeaders ();
42+ _httpHeaders. clearAll ();
4443 refreshTimeout ();
4544 return _socket;
4645 }
@@ -131,11 +130,8 @@ void HTTPConnection::closeConnection() {
131130 _connectionState = STATE_CLOSED;
132131 }
133132
134- if (_httpHeaders != NULL ) {
135- HTTPS_LOGD (" Free headers" );
136- delete _httpHeaders;
137- _httpHeaders = NULL ;
138- }
133+ HTTPS_LOGD (" Free headers" );
134+ _httpHeaders.clearAll ();
139135
140136 if (_wsHandler != nullptr ) {
141137 HTTPS_LOGD (" Free WS Handler" );
@@ -408,7 +404,7 @@ void HTTPConnection::loop() {
408404 } else {
409405 int idxColon = _parserLine.text .find (' :' );
410406 if ( (idxColon != std::string::npos) && (_parserLine.text [idxColon+1 ]==' ' ) ) {
411- _httpHeaders-> set (new HTTPHeader (
407+ _httpHeaders. set (new HTTPHeader (
412408 _parserLine.text .substr (0 , idxColon),
413409 _parserLine.text .substr (idxColon+2 )
414410 ));
@@ -441,7 +437,7 @@ void HTTPConnection::loop() {
441437 // Check for client's request to keep-alive if we have a handler function.
442438 if (resolvedResource.getMatchingNode ()->_nodeType == HANDLER_CALLBACK) {
443439 // Did the client set connection:keep-alive?
444- HTTPHeader * connectionHeader = _httpHeaders-> get (" Connection" );
440+ HTTPHeader * connectionHeader = _httpHeaders. get (" Connection" );
445441 std::string connectionHeaderValue = " " ;
446442 if (connectionHeader != NULL ) {
447443 connectionHeaderValue += connectionHeader->_value ;
@@ -466,7 +462,7 @@ void HTTPConnection::loop() {
466462 // Create request context
467463 HTTPRequest req = HTTPRequest (
468464 this ,
469- _httpHeaders,
465+ & _httpHeaders,
470466 resolvedResource.getMatchingNode (),
471467 _httpMethod,
472468 resolvedResource.getParams (),
@@ -549,7 +545,7 @@ void HTTPConnection::loop() {
549545 // Refresh the timeout for the new request
550546 refreshTimeout ();
551547 // Reset headers for the new connection
552- _httpHeaders-> clearAll ();
548+ _httpHeaders. clearAll ();
553549 // Go back to initial state
554550 _connectionState = STATE_INITIAL;
555551 }
@@ -604,11 +600,11 @@ void HTTPConnection::loop() {
604600
605601bool HTTPConnection::checkWebsocket () {
606602 if (_httpMethod == " GET" &&
607- !_httpHeaders-> getValue (" Host" ).empty () &&
608- _httpHeaders-> getValue (" Upgrade" ) == " websocket" &&
609- _httpHeaders-> getValue (" Connection" ).find (" Upgrade" ) != std::string::npos &&
610- !_httpHeaders-> getValue (" Sec-WebSocket-Key" ).empty () &&
611- _httpHeaders-> getValue (" Sec-WebSocket-Version" ) == " 13" ) {
603+ !_httpHeaders. getValue (" Host" ).empty () &&
604+ _httpHeaders. getValue (" Upgrade" ) == " websocket" &&
605+ _httpHeaders. getValue (" Connection" ).find (" Upgrade" ) != std::string::npos &&
606+ !_httpHeaders. getValue (" Sec-WebSocket-Key" ).empty () &&
607+ _httpHeaders. getValue (" Sec-WebSocket-Version" ) == " 13" ) {
612608
613609 HTTPS_LOGI (" Upgrading to WS, FID=%d" , _socket);
614610 return true ;
0 commit comments