| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,6 @@ HTTPConnection::HTTPConnection(ResourceResolver * resResolver): | |||
| 12 | 12 | ||
| 13 | 13 | _connectionState = STATE_UNDEFINED; | |
| 14 | 14 | _clientState = CSTATE_UNDEFINED; | |
| 15 | - _httpHeaders = NULL; | ||
| 16 | 15 | _defaultHeaders = NULL; | |
| 17 | 16 | _isKeepAlive = false; | |
| 18 | 17 | _lastTransmissionTS = millis(); | |
@@ -40,7 +39,7 @@ int HTTPConnection::initialize(int serverSocketID, HTTPHeaders *defaultHeaders) | |||
| 40 | 39 | if (_socket >= 0) { | |
| 41 | 40 | HTTPS_LOGI("New connection. Socket FID=%d", _socket); | |
| 42 | 41 | _connectionState = STATE_INITIAL; | |
| 43 | - _httpHeaders = new HTTPHeaders(); | ||
| 42 | + _httpHeaders.clearAll(); | ||
| 44 | 43 | refreshTimeout(); | |
| 45 | 44 | return _socket; | |
| 46 | 45 | } | |
@@ -131,11 +130,8 @@ void HTTPConnection::closeConnection() { | |||
| 131 | 130 | _connectionState = STATE_CLOSED; | |
| 132 | 131 | } | |
| 133 | 132 | ||
| 134 | - if (_httpHeaders != NULL) { | ||
| 135 | - HTTPS_LOGD("Free headers"); | ||
| 136 | - delete _httpHeaders; | ||
| 137 | - _httpHeaders = NULL; | ||
| 138 | - } | ||
| 133 | + HTTPS_LOGD("Free headers"); | ||
| 134 | + _httpHeaders.clearAll(); | ||
| 139 | 135 | ||
| 140 | 136 | if (_wsHandler != nullptr) { | |
| 141 | 137 | HTTPS_LOGD("Free WS Handler"); | |
@@ -408,7 +404,7 @@ void HTTPConnection::loop() { | |||
| 408 | 404 | } else { | |
| 409 | 405 | int idxColon = _parserLine.text.find(':'); | |
| 410 | 406 | if ( (idxColon != std::string::npos) && (_parserLine.text[idxColon+1]==' ') ) { | |
| 411 | - _httpHeaders->set(new HTTPHeader( | ||
| 407 | + _httpHeaders.set(new HTTPHeader( | ||
| 412 | 408 | _parserLine.text.substr(0, idxColon), | |
| 413 | 409 | _parserLine.text.substr(idxColon+2) | |
| 414 | 410 | )); | |
@@ -441,7 +437,7 @@ void HTTPConnection::loop() { | |||
| 441 | 437 | // Check for client's request to keep-alive if we have a handler function. | |
| 442 | 438 | if (resolvedResource.getMatchingNode()->_nodeType == HANDLER_CALLBACK) { | |
| 443 | 439 | // Did the client set connection:keep-alive? | |
| 444 | - HTTPHeader * connectionHeader = _httpHeaders->get("Connection"); | ||
| 440 | + HTTPHeader * connectionHeader = _httpHeaders.get("Connection"); | ||
| 445 | 441 | std::string connectionHeaderValue = ""; | |
| 446 | 442 | if (connectionHeader != NULL) { | |
| 447 | 443 | connectionHeaderValue += connectionHeader->_value; | |
@@ -466,7 +462,7 @@ void HTTPConnection::loop() { | |||
| 466 | 462 | // Create request context | |
| 467 | 463 | HTTPRequest req = HTTPRequest( | |
| 468 | 464 | this, | |
| 469 | - _httpHeaders, | ||
| 465 | + &_httpHeaders, | ||
| 470 | 466 | resolvedResource.getMatchingNode(), | |
| 471 | 467 | _httpMethod, | |
| 472 | 468 | resolvedResource.getParams(), | |
@@ -549,7 +545,7 @@ void HTTPConnection::loop() { | |||
| 549 | 545 | // Refresh the timeout for the new request | |
| 550 | 546 | refreshTimeout(); | |
| 551 | 547 | // Reset headers for the new connection | |
| 552 | - _httpHeaders->clearAll(); | ||
| 548 | + _httpHeaders.clearAll(); | ||
| 553 | 549 | // Go back to initial state | |
| 554 | 550 | _connectionState = STATE_INITIAL; | |
| 555 | 551 | } | |
@@ -604,11 +600,11 @@ void HTTPConnection::loop() { | |||
| 604 | 600 | ||
| 605 | 601 | bool HTTPConnection::checkWebsocket() { | |
| 606 | 602 | 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") { | ||
| 612 | 608 | ||
| 613 | 609 | HTTPS_LOGI("Upgrading to WS, FID=%d", _socket); | |
| 614 | 610 | return true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,7 +149,7 @@ class HTTPConnection : private ConnectionContext { | |||
| 149 | 149 | // HTTP properties: Method, Request, Headers | |
| 150 | 150 | std::string _httpMethod; | |
| 151 | 151 | std::string _httpResource; | |
| 152 | - HTTPHeaders * _httpHeaders; | ||
| 152 | + HTTPHeaders _httpHeaders; | ||
| 153 | 153 | ||
| 154 | 154 | // Default headers that are applied to every response | |
| 155 | 155 | HTTPHeaders * _defaultHeaders; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,21 +88,8 @@ int HTTPSConnection::initialize(int serverSocketID, mbedtls_ssl_config *sslConfi | |||
| 88 | 88 | return -1; | |
| 89 | 89 | } | |
| 90 | 90 | ||
| 91 | - int HTTPSConnection::shutdown() { | ||
| 92 | - int res; | ||
| 93 | - while (true) { | ||
| 94 | - res = mbedtls_ssl_close_notify(&_ssl); | ||
| 95 | - if (res == 0) { | ||
| 96 | - return 1; | ||
| 97 | - } | ||
| 98 | - if (res != MBEDTLS_ERR_SSL_WANT_WRITE) { | ||
| 99 | - return 0; | ||
| 100 | - } | ||
| 101 | - } | ||
| 102 | - } | ||
| 103 | 91 | ||
| 104 | 92 | void HTTPSConnection::closeConnection() { | |
| 105 | - | ||
| 106 | 93 | // FIXME: Copy from HTTPConnection, could be done better probably | |
| 107 | 94 | if (_connectionState != STATE_ERROR && _connectionState != STATE_CLOSED) { | |
| 108 | 95 | ||
@@ -118,8 +105,8 @@ void HTTPSConnection::closeConnection() { | |||
| 118 | 105 | ||
| 119 | 106 | // Try to tear down SSL while we are in the _shutdownTS timeout period or if an error occurred | |
| 120 | 107 | if (_sslCreated) { | |
| 121 | - if (_connectionState == STATE_ERROR || shutdown() == 0) { | ||
| 122 | - // SSL shutdown will return 1 as soon as the client answered with close notify | ||
| 108 | + if (_connectionState == STATE_ERROR || mbedtls_ssl_close_notify(&_ssl) == 0) { | ||
| 109 | + // SSL shutdown will return 0 as soon as the client answered with close notify | ||
| 123 | 110 | // This means we are safe to close the socket | |
| 124 | 111 | mbedtls_ssl_free(&_ssl); | |
| 125 | 112 | _sslCreated = false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,7 +39,6 @@ class HTTPSConnection : public HTTPConnection { | |||
| 39 | 39 | virtual bool isSecure(); | |
| 40 | 40 | bool setup(mbedtls_ssl_config *sslConfig); | |
| 41 | 41 | bool handshake(); | |
| 42 | - int shutdown(); | ||
| 43 | 42 | ||
| 44 | 43 | protected: | |
| 45 | 44 | friend class HTTPRequest; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments