diff options
| author | Stefan Boberg <[email protected]> | 2021-10-18 19:43:40 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-18 19:43:40 +0200 |
| commit | 24c70998a94ebf00bdd219da05f35d75d93e2ea2 (patch) | |
| tree | 558502750046473760d3c522cb373848a0341b44 /zenhttp/httpasio.cpp | |
| parent | project store: DELETE {project} request now produces a correct HTTP response (diff) | |
| download | zen-24c70998a94ebf00bdd219da05f35d75d93e2ea2.tar.xz zen-24c70998a94ebf00bdd219da05f35d75d93e2ea2.zip | |
httpasio: Implemented some handling for Expect: header
We do not actually send a 100 CONTINUE still though since this is not necessary with the changes we made UE-side
Also tweaked some of the internal request state management and added some debug logging
Diffstat (limited to 'zenhttp/httpasio.cpp')
| -rw-r--r-- | zenhttp/httpasio.cpp | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/zenhttp/httpasio.cpp b/zenhttp/httpasio.cpp index 12fbdb61e..ce6503a96 100644 --- a/zenhttp/httpasio.cpp +++ b/zenhttp/httpasio.cpp @@ -2,14 +2,17 @@ #include "httpasio.h" +#include <zencore/logging.h> #include <zenhttp/httpserver.h> -#include <conio.h> -#include <zencore/logging.h> +#include <deque> +#include <memory_resource> +ZEN_THIRD_PARTY_INCLUDES_START +#include <conio.h> #include <http_parser.h> #include <asio.hpp> -#include <deque> +ZEN_THIRD_PARTY_INCLUDES_END namespace zen::asio_http { @@ -24,6 +27,7 @@ struct HttpServerConnection; static constinit uint32_t HashContentLength = HashStringAsLowerDjb2("Content-Length"sv); static constinit uint32_t HashContentType = HashStringAsLowerDjb2("Content-Type"sv); static constinit uint32_t HashAccept = HashStringAsLowerDjb2("Accept"sv); +static constinit uint32_t HashExpect = HashStringAsLowerDjb2("Expect"sv); static constinit uint32_t HashSession = HashStringAsLowerDjb2("UE-Session"sv); static constinit uint32_t HashRequest = HashStringAsLowerDjb2("UE-Request"sv); @@ -31,7 +35,7 @@ inline spdlog::logger& InitLogger() { spdlog::logger& Logger = logging::Get("asio"); - // Logger.set_level(spdlog::level::trace); + //Logger.set_level(spdlog::level::trace); return Logger; } @@ -144,7 +148,6 @@ private: }; HttpServerConnection& m_Connection; - char m_HeaderBuffer[512]; char* m_HeaderCursor = m_HeaderBuffer; char* m_Url = nullptr; size_t m_UrlLength = 0; @@ -158,13 +161,15 @@ private: int8_t m_ContentLengthHeaderIndex; int8_t m_AcceptHeaderIndex; int8_t m_ContentTypeHeaderIndex; - int m_RequestId = -1; + HttpVerb m_RequestVerb; + bool m_KeepAlive = false; + bool m_Expect100Continue = false; + int m_RequestId = -1; Oid m_SessionId{}; IoBuffer m_BodyBuffer; - uint64_t m_BodyPosition; + uint64_t m_BodyPosition = 0; http_parser m_Parser; - HttpVerb m_RequestVerb; - bool m_KeepAlive = false; + char m_HeaderBuffer[512]; void AppendInputBytes(const char* Data, size_t Bytes); void AppendCurrentHeader(); @@ -327,6 +332,7 @@ HttpServerConnection::HttpServerConnection(HttpAsioServerImpl& Server, std::uniq HttpServerConnection::~HttpServerConnection() { + ZEN_TRACE("destroying connection #{}", m_ConnectionId); } void @@ -701,6 +707,18 @@ HttpRequest::AppendCurrentHeader() { std::from_chars(HeaderValue.data(), HeaderValue.data() + HeaderValue.size(), m_RequestId); } + else if (HeaderHash == HashExpect) + { + if (HeaderValue == "100-continue"sv) + { + // We don't currently do anything with this + m_Expect100Continue = true; + } + else + { + ZEN_INFO("Unexpected expect - Expect: {}", HeaderValue); + } + } m_Headers.emplace_back(HeaderName, HeaderValue); } @@ -744,10 +762,6 @@ HttpRequest::OnHeadersComplete() { m_BodyBuffer = IoBuffer(ContentLength); } - else - { - m_BodyBuffer = {}; - } m_BodyBuffer.SetContentType(ContentType()); @@ -827,13 +841,14 @@ HttpRequest::ResetState() m_CurrentHeaderName = nullptr; m_Url = nullptr; m_UrlLength = 0; + m_QueryString = nullptr; + m_QueryLength = 0; m_ContentLengthHeaderIndex = -1; m_AcceptHeaderIndex = -1; m_ContentTypeHeaderIndex = -1; - - m_BodyBuffer = {}; - m_BodyPosition = 0; - + m_Expect100Continue = false; + m_BodyBuffer = {}; + m_BodyPosition = 0; m_Headers.clear(); } @@ -1115,6 +1130,7 @@ HttpAsioServerImpl::RouteRequest(std::string_view Url) namespace zen { HttpAsioServer::HttpAsioServer() : m_Impl(std::make_unique<asio_http::HttpAsioServerImpl>()) { + ZEN_DEBUG("Request object size: {} ({:#x})", sizeof(asio_http::HttpRequest), sizeof(asio_http::HttpRequest)); } HttpAsioServer::~HttpAsioServer() |