From e054954475496f540197a1b6a8d6b40285a824be Mon Sep 17 00:00:00 2001 From: Slavey Karadzhov Date: Mon, 15 Nov 2021 15:22:40 +0100 Subject: [PATCH] Fixed a bug with request headers not being reset. --- Sming/Components/Network/src/Network/Http/HttpRequest.cpp | 1 + .../Network/src/Network/Http/HttpServerConnection.cpp | 1 + samples/HttpServer_Plugins/app/application.cpp | 3 +++ 3 files changed, 5 insertions(+) diff --git a/Sming/Components/Network/src/Network/Http/HttpRequest.cpp b/Sming/Components/Network/src/Network/Http/HttpRequest.cpp index 48e6d1a453..cf330c6867 100644 --- a/Sming/Components/Network/src/Network/Http/HttpRequest.cpp +++ b/Sming/Components/Network/src/Network/Http/HttpRequest.cpp @@ -64,6 +64,7 @@ void HttpRequest::reset() postParams.clear(); files.clear(); + headers.clear(); } String HttpRequest::toString() const diff --git a/Sming/Components/Network/src/Network/Http/HttpServerConnection.cpp b/Sming/Components/Network/src/Network/Http/HttpServerConnection.cpp index c6156fd1a5..2dacf1a12a 100644 --- a/Sming/Components/Network/src/Network/Http/HttpServerConnection.cpp +++ b/Sming/Components/Network/src/Network/Http/HttpServerConnection.cpp @@ -28,6 +28,7 @@ int HttpServerConnection::onMessageBegin(http_parser* parser) response.reset(); // ... and Request + request.reset(); request.setMethod((const HttpMethod)parser->method); // and temp data... diff --git a/samples/HttpServer_Plugins/app/application.cpp b/samples/HttpServer_Plugins/app/application.cpp index 529933e8eb..04af70bb83 100644 --- a/samples/HttpServer_Plugins/app/application.cpp +++ b/samples/HttpServer_Plugins/app/application.cpp @@ -18,6 +18,9 @@ void echoContentBody(HttpRequest& request, HttpResponse& response) auto body = request.getBody(); debug_d("Got content (after modifications): %s", body.c_str()); + if(body.length() == 0) { + body = F("Echo"); + } response.headers[HTTP_HEADER_CONTENT_TYPE] = request.headers[HTTP_HEADER_CONTENT_TYPE]; response.sendString(body); }