Implemented request bodies
This commit is contained in:
1 parent
fb84784d1c
commit
aa073c2385
10 files changed
+146
-22
No files matched your search
@@ -29,6 +29,10 @@ void ChunkedResponseHandler::requestHeaderReceived(std::string_view key, std::st
|
||||
{
|
||||
}
|
||||
|
||||
void ChunkedResponseHandler::requestBodyReceived(std::string_view body)
|
||||
{
|
||||
}
|
||||
|
||||
void ChunkedResponseHandler::sendResponse()
|
||||
{
|
||||
ESP_LOGI(TAG, "sending response (header) for (%s:%hi)",
|
||||
|
||||
@@ -11,13 +11,14 @@
|
||||
// forward declarations
|
||||
class ClientConnection;
|
||||
|
||||
class ChunkedResponseHandler : public ResponseHandler
|
||||
class ChunkedResponseHandler final : public ResponseHandler
|
||||
{
|
||||
public:
|
||||
ChunkedResponseHandler(ClientConnection &clientConnection);
|
||||
~ChunkedResponseHandler() override;
|
||||
~ChunkedResponseHandler() final;
|
||||
|
||||
void requestHeaderReceived(std::string_view key, std::string_view value) final;
|
||||
void requestBodyReceived(std::string_view body) final;
|
||||
void sendResponse() final;
|
||||
|
||||
private:
|
||||
|
||||
@@ -30,6 +30,11 @@ void DebugResponseHandler::requestHeaderReceived(std::string_view key, std::stri
|
||||
m_requestHeaders.emplace_back(std::make_pair(std::string{key}, std::string{value}));
|
||||
}
|
||||
|
||||
void DebugResponseHandler::requestBodyReceived(std::string_view body)
|
||||
{
|
||||
m_requestBody += body;
|
||||
}
|
||||
|
||||
void DebugResponseHandler::sendResponse()
|
||||
{
|
||||
ESP_LOGI(TAG, "sending response for %.*s %.*s (%s:%hi)", m_method.size(), m_method.data(), m_path.size(), m_path.data(),
|
||||
@@ -56,10 +61,19 @@ void DebugResponseHandler::sendResponse()
|
||||
m_response += fmt::format( "<tr><th>{}</th><td>{}</td></tr>",
|
||||
pair.first, pair.second);
|
||||
|
||||
m_response += fmt::format( "</table>"
|
||||
m_response += "</table>"
|
||||
"</td>"
|
||||
"</tr>"
|
||||
"</tbody>"
|
||||
"</tr>";
|
||||
|
||||
if (!m_requestBody.empty())
|
||||
{
|
||||
m_response += fmt::format( "<tr>"
|
||||
"<th>Request body:</th>"
|
||||
"<td><pre>{}</pre></td>"
|
||||
"</tr>", m_requestBody);
|
||||
}
|
||||
|
||||
m_response += "</tbody>"
|
||||
"</table>"
|
||||
"<form method=\"GET\">"
|
||||
"<fieldset>"
|
||||
@@ -90,7 +104,7 @@ void DebugResponseHandler::sendResponse()
|
||||
"</fieldset>"
|
||||
"</form>"
|
||||
"</body>"
|
||||
"</html>");
|
||||
"</html>";
|
||||
|
||||
m_response = fmt::format("HTTP/1.1 200 Ok\r\n"
|
||||
"Content-Type: text/html\r\n"
|
||||
|
||||
@@ -13,13 +13,14 @@
|
||||
// forward declarations
|
||||
class ClientConnection;
|
||||
|
||||
class DebugResponseHandler : public ResponseHandler
|
||||
class DebugResponseHandler final : public ResponseHandler
|
||||
{
|
||||
public:
|
||||
DebugResponseHandler(ClientConnection &clientConnection, std::string_view method, std::string_view path, std::string_view protocol);
|
||||
~DebugResponseHandler() override;
|
||||
~DebugResponseHandler() final;
|
||||
|
||||
void requestHeaderReceived(std::string_view key, std::string_view value) final;
|
||||
void requestBodyReceived(std::string_view body) final;
|
||||
void sendResponse() final;
|
||||
|
||||
private:
|
||||
@@ -32,5 +33,7 @@ private:
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> m_requestHeaders;
|
||||
|
||||
std::string m_requestBody;
|
||||
|
||||
std::string m_response;
|
||||
};
|
||||
@@ -30,6 +30,10 @@ void ErrorResponseHandler::requestHeaderReceived(std::string_view key, std::stri
|
||||
{
|
||||
}
|
||||
|
||||
void ErrorResponseHandler::requestBodyReceived(std::string_view body)
|
||||
{
|
||||
}
|
||||
|
||||
void ErrorResponseHandler::sendResponse()
|
||||
{
|
||||
ESP_LOGI(TAG, "sending response for %.*s (%s:%hi)", m_path.size(), m_path.data(),
|
||||
|
||||
@@ -11,13 +11,14 @@
|
||||
// forward declarations
|
||||
class ClientConnection;
|
||||
|
||||
class ErrorResponseHandler : public ResponseHandler
|
||||
class ErrorResponseHandler final : public ResponseHandler
|
||||
{
|
||||
public:
|
||||
ErrorResponseHandler(ClientConnection &clientConnection, std::string_view path);
|
||||
~ErrorResponseHandler() override;
|
||||
~ErrorResponseHandler() final;
|
||||
|
||||
void requestHeaderReceived(std::string_view key, std::string_view value) final;
|
||||
void requestBodyReceived(std::string_view body) final;
|
||||
void sendResponse() final;
|
||||
|
||||
private:
|
||||
|
||||
@@ -29,6 +29,10 @@ void RootResponseHandler::requestHeaderReceived(std::string_view key, std::strin
|
||||
{
|
||||
}
|
||||
|
||||
void RootResponseHandler::requestBodyReceived(std::string_view body)
|
||||
{
|
||||
}
|
||||
|
||||
void RootResponseHandler::sendResponse()
|
||||
{
|
||||
ESP_LOGI(TAG, "sending response for (%s:%hi)",
|
||||
@@ -40,8 +44,10 @@ void RootResponseHandler::sendResponse()
|
||||
"</head>"
|
||||
"<body>"
|
||||
"<h1>asio test webserver</h1>"
|
||||
"<a href=\"/debug\">Debug</a>"
|
||||
"<a href=\"/chunked\">Chunked</a>"
|
||||
"<ul>"
|
||||
"<li><a href=\"/debug\">Debug</a></li>"
|
||||
"<li><a href=\"/chunked\">Chunked</a></li>"
|
||||
"</ul>"
|
||||
"</body>"
|
||||
"</html>");
|
||||
|
||||
|
||||
@@ -11,13 +11,14 @@
|
||||
// forward declarations
|
||||
class ClientConnection;
|
||||
|
||||
class RootResponseHandler : public ResponseHandler
|
||||
class RootResponseHandler final : public ResponseHandler
|
||||
{
|
||||
public:
|
||||
RootResponseHandler(ClientConnection &clientConnection);
|
||||
~RootResponseHandler() override;
|
||||
|
||||
void requestHeaderReceived(std::string_view key, std::string_view value) final;
|
||||
void requestBodyReceived(std::string_view body) final;
|
||||
void sendResponse() final;
|
||||
|
||||
private:
|
||||
|
||||
Reference in new issue
Block a user