aboutsummaryrefslogtreecommitdiff
path: root/zenhttp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-10-19 22:27:19 +0200
committerStefan Boberg <[email protected]>2021-10-19 22:27:19 +0200
commitd5ec07a2ab50185b0e33e14da87cf54e8e7cd962 (patch)
tree6ba4acb74ee4785b3487952c44eba5a5e7a9180e /zenhttp
parentSome gc interface stubs (diff)
parentcas: Factored out OpenOrCreateManifest (diff)
downloadzen-d5ec07a2ab50185b0e33e14da87cf54e8e7cd962.tar.xz
zen-d5ec07a2ab50185b0e33e14da87cf54e8e7cd962.zip
Merge branch 'gc' of https://github.com/EpicGames/zen into gc
Diffstat (limited to 'zenhttp')
-rw-r--r--zenhttp/httpasio.cpp50
-rw-r--r--zenhttp/httpsys.cpp12
2 files changed, 43 insertions, 19 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()
diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp
index f3568bbd1..cdf9e0a39 100644
--- a/zenhttp/httpsys.cpp
+++ b/zenhttp/httpsys.cpp
@@ -341,8 +341,6 @@ HttpMessageResponseRequest::~HttpMessageResponseRequest()
void
HttpMessageResponseRequest::InitializeForPayload(uint16_t ResponseCode, std::span<IoBuffer> BlobList)
{
- m_ResponseCode = ResponseCode;
-
const uint32_t ChunkCount = gsl::narrow<uint32_t>(BlobList.size());
m_HttpDataChunks.reserve(ChunkCount);
@@ -407,6 +405,16 @@ HttpMessageResponseRequest::InitializeForPayload(uint16_t ResponseCode, std::spa
m_RemainingChunkCount = gsl::narrow<uint32_t>(m_HttpDataChunks.size());
m_TotalDataSize = LocalDataSize;
+
+ if (m_TotalDataSize == 0 && ResponseCode == 200)
+ {
+ // Some HTTP clients really don't like empty responses unless a 204 response is sent
+ m_ResponseCode = uint16_t(HttpResponseCode::NoContent);
+ }
+ else
+ {
+ m_ResponseCode = ResponseCode;
+ }
}
void