diff options
| author | Per Larsson <[email protected]> | 2021-12-14 12:34:47 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-12-14 12:34:47 +0100 |
| commit | b6c6568e1618f10d2160d836b65e35586e3c740f (patch) | |
| tree | f6a929cf918850bbba87d0ee67cd3482b2d50e24 /zenhttp | |
| parent | Fixed bug in z$ service returning partial cache records and enable small obje... (diff) | |
| parent | Partial revert b363c5b (diff) | |
| download | zen-b6c6568e1618f10d2160d836b65e35586e3c740f.tar.xz zen-b6c6568e1618f10d2160d836b65e35586e3c740f.zip | |
Merged main.
Diffstat (limited to 'zenhttp')
| -rw-r--r-- | zenhttp/httpasio.cpp | 37 | ||||
| -rw-r--r-- | zenhttp/httpclient.cpp | 4 | ||||
| -rw-r--r-- | zenhttp/httpnull.cpp | 30 | ||||
| -rw-r--r-- | zenhttp/httpserver.cpp | 2 | ||||
| -rw-r--r-- | zenhttp/httpshared.cpp | 2 | ||||
| -rw-r--r-- | zenhttp/httpsys.cpp | 6 | ||||
| -rw-r--r-- | zenhttp/include/zenhttp/httpclient.h | 2 | ||||
| -rw-r--r-- | zenhttp/include/zenhttp/httpserver.h | 2 | ||||
| -rw-r--r-- | zenhttp/include/zenhttp/httpshared.h | 5 | ||||
| -rw-r--r-- | zenhttp/workthreadpool.h | 1 | ||||
| -rw-r--r-- | zenhttp/xmake.lua | 5 |
11 files changed, 62 insertions, 34 deletions
diff --git a/zenhttp/httpasio.cpp b/zenhttp/httpasio.cpp index 08cefc3bc..e1d417d06 100644 --- a/zenhttp/httpasio.cpp +++ b/zenhttp/httpasio.cpp @@ -10,7 +10,9 @@ #include <memory_resource> ZEN_THIRD_PARTY_INCLUDES_START -#include <conio.h> +#if ZEN_PLATFORM_WINDOWS +# include <conio.h> +#endif #include <http_parser.h> #include <asio.hpp> ZEN_THIRD_PARTY_INCLUDES_END @@ -405,7 +407,7 @@ HttpServerConnection::OnDataReceived(const asio::error_code& Ec, [[maybe_unused] ZEN_TRACE_VERBOSE("on data received, connection '{}', request '{}', thread '{}', bytes '{}'", m_ConnectionId, m_RequestCounter.load(std::memory_order_relaxed), - GetCurrentThreadId(), + zen::GetCurrentThreadId(), NiceBytes(ByteCount)); while (m_RequestBuffer.size()) @@ -443,7 +445,7 @@ HttpServerConnection::OnResponseDataSent(const asio::error_code& Ec, [[maybe_unu ZEN_TRACE_VERBOSE("on data sent, connection '{}', request '{}', thread '{}', bytes '{}'", m_ConnectionId, m_RequestCounter.load(std::memory_order_relaxed), - GetCurrentThreadId(), + zen::GetCurrentThreadId(), NiceBytes(ByteCount)); if (!m_RequestData.IsKeepAlive()) @@ -1071,7 +1073,7 @@ HttpAsioServerRequest::WriteResponse(HttpResponseCode ResponseCode) m_Response.reset(new HttpResponse(HttpContentType::kBinary)); std::array<IoBuffer, 0> Empty; - m_Response->InitializeForPayload((UINT16)ResponseCode, Empty); + m_Response->InitializeForPayload((uint16_t)ResponseCode, Empty); } void @@ -1080,7 +1082,7 @@ HttpAsioServerRequest::WriteResponse(HttpResponseCode ResponseCode, HttpContentT ZEN_ASSERT(!m_Response); m_Response.reset(new HttpResponse(ContentType)); - m_Response->InitializeForPayload((UINT16)ResponseCode, Blobs); + m_Response->InitializeForPayload((uint16_t)ResponseCode, Blobs); } void @@ -1220,6 +1222,13 @@ HttpAsioServer::Run(bool IsInteractive) { const bool TestMode = !IsInteractive; + int WaitTimeout = -1; + if (!TestMode) + { + WaitTimeout = 1000; + } + +#if ZEN_PLATFORM_WINDOWS if (TestMode == false) { zen::logging::ConsoleLog().info("Zen Server running (asio HTTP). Press ESC or Q to quit"); @@ -1227,13 +1236,6 @@ HttpAsioServer::Run(bool IsInteractive) do { - int WaitTimeout = -1; - - if (!TestMode) - { - WaitTimeout = 1000; - } - if (!TestMode && _kbhit() != 0) { char c = (char)_getch(); @@ -1246,6 +1248,17 @@ HttpAsioServer::Run(bool IsInteractive) m_ShutdownEvent.Wait(WaitTimeout); } while (!IsApplicationExitRequested()); +#else + if (TestMode == false) + { + zen::logging::ConsoleLog().info("Zen Server running (asio HTTP). Ctrl-C to quit"); + } + + do + { + m_ShutdownEvent.Wait(WaitTimeout); + } while (!IsApplicationExitRequested()); +#endif } void diff --git a/zenhttp/httpclient.cpp b/zenhttp/httpclient.cpp index 6e915e613..e6813d407 100644 --- a/zenhttp/httpclient.cpp +++ b/zenhttp/httpclient.cpp @@ -22,7 +22,7 @@ using namespace std::literals; HttpClient::Response FromCprResponse(cpr::Response& InResponse) { - return {.StatusCode = InResponse.status_code}; + return {.StatusCode = int(InResponse.status_code)}; } ////////////////////////////////////////////////////////////////////////// @@ -130,7 +130,7 @@ HttpClient::TransactPackage(std::string_view Url, CbPackage Package) ResponseBuffer.SetContentType(ContentType); } - return {.StatusCode = FilterResponse.status_code, .ResponsePayload = ResponseBuffer}; + return {.StatusCode = int(FilterResponse.status_code), .ResponsePayload = ResponseBuffer}; } HttpClient::Response diff --git a/zenhttp/httpnull.cpp b/zenhttp/httpnull.cpp index e49051ac5..31b13a6ce 100644 --- a/zenhttp/httpnull.cpp +++ b/zenhttp/httpnull.cpp @@ -2,9 +2,12 @@ #include "httpnull.h" -#include <conio.h> #include <zencore/logging.h> +#if ZEN_PLATFORM_WINDOWS +# include <conio.h> +#endif + namespace zen { HttpNullServer::HttpNullServer() @@ -32,6 +35,13 @@ HttpNullServer::Run(bool IsInteractiveSession) { const bool TestMode = !IsInteractiveSession; + int WaitTimeout = -1; + if (!TestMode) + { + WaitTimeout = 1000; + } + +#if ZEN_PLATFORM_WINDOWS if (TestMode == false) { zen::logging::ConsoleLog().info("Zen Server running (null HTTP). Press ESC or Q to quit"); @@ -39,13 +49,6 @@ HttpNullServer::Run(bool IsInteractiveSession) do { - int WaitTimeout = -1; - - if (!TestMode) - { - WaitTimeout = 1000; - } - if (!TestMode && _kbhit() != 0) { char c = (char)_getch(); @@ -58,6 +61,17 @@ HttpNullServer::Run(bool IsInteractiveSession) m_ShutdownEvent.Wait(WaitTimeout); } while (!IsApplicationExitRequested()); +#else + if (TestMode == false) + { + zen::logging::ConsoleLog().info("Zen Server running (null HTTP). Ctrl-C to quit"); + } + + do + { + m_ShutdownEvent.Wait(WaitTimeout); + } while (!IsApplicationExitRequested()); +#endif } void diff --git a/zenhttp/httpserver.cpp b/zenhttp/httpserver.cpp index b1bf99bce..5712563c3 100644 --- a/zenhttp/httpserver.cpp +++ b/zenhttp/httpserver.cpp @@ -18,8 +18,6 @@ #include <zencore/thread.h> #include <zenhttp/httpshared.h> -#include <conio.h> -#include <new.h> #include <charconv> #include <mutex> #include <span> diff --git a/zenhttp/httpshared.cpp b/zenhttp/httpshared.cpp index c703409af..ab1463559 100644 --- a/zenhttp/httpshared.cpp +++ b/zenhttp/httpshared.cpp @@ -109,7 +109,7 @@ FormatPackageMessage(const CbPackage& Data) } } - return std::move(ResponseBuffers); + return ResponseBuffers; } CbPackage diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index 78cf253cc..a17c2661c 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -1187,7 +1187,7 @@ HttpSysServerRequest::HttpSysServerRequest(HttpSysTransaction& Tx, HttpService& const HTTP_REQUEST* HttpRequestPtr = Tx.HttpRequest(); const int PrefixLength = Service.UriPrefixLength(); - const int AbsPathLength = HttpRequestPtr->CookedUrl.AbsPathLength / sizeof(char16_t); + const int AbsPathLength = HttpRequestPtr->CookedUrl.AbsPathLength / sizeof(wchar_t); HttpContentType AcceptContentType = HttpContentType::kUnknownContentType; @@ -1197,7 +1197,7 @@ HttpSysServerRequest::HttpSysServerRequest(HttpSysTransaction& Tx, HttpService& // with utf8. This is overhead which I'd prefer to avoid but for now we just have // to live with it - WideToUtf8({(char16_t*)HttpRequestPtr->CookedUrl.pAbsPath + PrefixLength, gsl::narrow<size_t>(AbsPathLength - PrefixLength)}, + WideToUtf8({(wchar_t*)HttpRequestPtr->CookedUrl.pAbsPath + PrefixLength, gsl::narrow<size_t>(AbsPathLength - PrefixLength)}, m_UriUtf8); std::string_view UriSuffix8{m_UriUtf8}; @@ -1234,7 +1234,7 @@ HttpSysServerRequest::HttpSysServerRequest(HttpSysTransaction& Tx, HttpService& { --QueryStringLength; // We skip the leading question mark - WideToUtf8({(char16_t*)(HttpRequestPtr->CookedUrl.pQueryString) + 1, QueryStringLength / sizeof(char16_t)}, m_QueryStringUtf8); + WideToUtf8({(wchar_t*)(HttpRequestPtr->CookedUrl.pQueryString) + 1, QueryStringLength / sizeof(wchar_t)}, m_QueryStringUtf8); } else { diff --git a/zenhttp/include/zenhttp/httpclient.h b/zenhttp/include/zenhttp/httpclient.h index 9ece86111..8316a9b9f 100644 --- a/zenhttp/include/zenhttp/httpclient.h +++ b/zenhttp/include/zenhttp/httpclient.h @@ -8,8 +8,6 @@ #include <zencore/uid.h> #include <zenhttp/httpcommon.h> -#include <zencore/windows.h> - ZEN_THIRD_PARTY_INCLUDES_START #include <cpr/cpr.h> ZEN_THIRD_PARTY_INCLUDES_END diff --git a/zenhttp/include/zenhttp/httpserver.h b/zenhttp/include/zenhttp/httpserver.h index b32359d67..902310f04 100644 --- a/zenhttp/include/zenhttp/httpserver.h +++ b/zenhttp/include/zenhttp/httpserver.h @@ -48,7 +48,7 @@ public: if (Key.size() == ParamName.size()) { - if (0 == _strnicmp(Key.data(), ParamName.data(), Key.size())) + if (0 == StrCaseCompare(Key.data(), ParamName.data(), Key.size())) { return Kv.second; } diff --git a/zenhttp/include/zenhttp/httpshared.h b/zenhttp/include/zenhttp/httpshared.h index 2e728577d..a6a61485f 100644 --- a/zenhttp/include/zenhttp/httpshared.h +++ b/zenhttp/include/zenhttp/httpshared.h @@ -36,7 +36,10 @@ struct CbPackageHeader static_assert(sizeof(CbPackageHeader) == 16); -static constinit uint32_t kCbPkgMagic = 0xaa77aacc; +enum : uint32_t +{ + kCbPkgMagic = 0xaa77aacc +}; struct CbAttachmentEntry { diff --git a/zenhttp/workthreadpool.h b/zenhttp/workthreadpool.h index 6581cc08f..834339d50 100644 --- a/zenhttp/workthreadpool.h +++ b/zenhttp/workthreadpool.h @@ -6,7 +6,6 @@ #include <zencore/blockingqueue.h> #include <zencore/refcount.h> -#include <zencore/windows.h> #include <exception> #include <functional> diff --git a/zenhttp/xmake.lua b/zenhttp/xmake.lua index fff4fb526..a94069c17 100644 --- a/zenhttp/xmake.lua +++ b/zenhttp/xmake.lua @@ -3,5 +3,8 @@ target('zenhttp') add_files("**.cpp") add_includedirs("include", {public=true}) add_deps("zencore") - add_packages("vcpkg::gsl-lite") + add_packages( + "vcpkg::gsl-lite", + "vcpkg::http-parser" + ) add_options("httpsys")
\ No newline at end of file |