Add example chunked encoding response
This commit is contained in:
1 parent
7b93dfa6cf
commit
fb84784d1c
14 files changed
+216
-11
No files matched your search
@@ -1,10 +1,13 @@
|
||||
#include "clientconnection.h"
|
||||
|
||||
// system includes
|
||||
#include <cstdio>
|
||||
#include <utility>
|
||||
|
||||
// esp-idf includes
|
||||
#include <esp_log.h>
|
||||
|
||||
// local includes
|
||||
#include "webserver.h"
|
||||
#include "responsehandler.h"
|
||||
|
||||
@@ -19,12 +22,16 @@ ClientConnection::ClientConnection(Webserver &webserver, asio::ip::tcp::socket s
|
||||
{
|
||||
ESP_LOGI(TAG, "new client (%s:%hi)",
|
||||
m_remote_endpoint.address().to_string().c_str(), m_remote_endpoint.port());
|
||||
|
||||
m_webserver.m_clients++;
|
||||
}
|
||||
|
||||
ClientConnection::~ClientConnection()
|
||||
{
|
||||
ESP_LOGI(TAG, "client destroyed (%s:%hi)",
|
||||
m_remote_endpoint.address().to_string().c_str(), m_remote_endpoint.port());
|
||||
|
||||
m_webserver.m_clients--;
|
||||
}
|
||||
|
||||
void ClientConnection::start()
|
||||
@@ -42,7 +49,7 @@ void ClientConnection::responseFinished(std::error_code ec)
|
||||
return;
|
||||
}
|
||||
|
||||
if constexpr (false) // Connection: Keep
|
||||
if constexpr (true) // Connection: Keep
|
||||
{
|
||||
// ESP_LOGD(TAG, "state changed to RequestLine");
|
||||
m_state = State::RequestLine;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <asio.hpp>
|
||||
// system includes
|
||||
#include <memory>
|
||||
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
|
||||
// esp-idf includes
|
||||
#include <asio.hpp>
|
||||
|
||||
class Webserver;
|
||||
class ResponseHandler;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <string_view>
|
||||
|
||||
class ResponseHandler
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
#include "webserver.h"
|
||||
|
||||
// esp-idf includes
|
||||
#include <esp_log.h>
|
||||
|
||||
// local includes
|
||||
#include "clientconnection.h"
|
||||
|
||||
namespace {
|
||||
constexpr const char * const TAG = "ASIO_WEBSERVER";
|
||||
} // namespace
|
||||
|
||||
Webserver::Webserver(asio::io_context &io_context, short port)
|
||||
: m_acceptor{io_context, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port)}
|
||||
Webserver::Webserver(asio::io_context &io_context, unsigned short port) :
|
||||
m_acceptor{io_context, asio::ip::tcp::endpoint{asio::ip::tcp::v4(), port}}
|
||||
{
|
||||
ESP_LOGI(TAG, "create webserver on port %hi", port);
|
||||
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <atomic>
|
||||
|
||||
// esp-idf includes
|
||||
#include <asio.hpp>
|
||||
|
||||
// forward declares
|
||||
class ResponseHandler;
|
||||
class ClientConnection;
|
||||
|
||||
class Webserver
|
||||
{
|
||||
public:
|
||||
Webserver(asio::io_context& io_context, short port);
|
||||
Webserver(asio::io_context& io_context, unsigned short port);
|
||||
virtual ~Webserver() = default;
|
||||
|
||||
virtual std::unique_ptr<ResponseHandler> makeResponseHandler(ClientConnection &clientConnection, std::string_view method, std::string_view path, std::string_view protocol) = 0;
|
||||
|
||||
protected:
|
||||
friend class ClientConnection;
|
||||
std::atomic<int> m_clients;
|
||||
|
||||
private:
|
||||
void doAccept();
|
||||
void acceptClient(std::error_code ec, asio::ip::tcp::socket socket);
|
||||
|
||||
Reference in new issue
Block a user