From c55df8f9cdded0da0dc6a4d6a42e043e46e9b27f Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Wed, 15 Sep 2021 12:51:01 +0200 Subject: GetWindowsErrorAsString() -> GetErrorAsString() --- zenhttp/httpsys.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zenhttp/httpsys.cpp') diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index e8da9cb90..80e1b8ee9 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -418,7 +418,7 @@ HttpMessageResponseRequest::HandleCompletion(ULONG IoResult, ULONG_PTR NumberOfB if (IoResult) { - ZEN_WARN("response aborted due to error: '{}'", GetWindowsErrorAsString(IoResult)); + ZEN_WARN("response aborted due to error: '{}'", GetErrorAsString(IoResult)); // if one transmit failed there's really no need to go on return nullptr; -- cgit v1.2.3 From 814b2775763c60238b6c5721a843d7429750fe75 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Wed, 15 Sep 2021 12:51:21 +0200 Subject: MakeWin32ErrorCode() -> MakeErrorCode() --- zenhttp/httpsys.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'zenhttp/httpsys.cpp') diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index 80e1b8ee9..533971c4c 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -556,7 +556,7 @@ HttpMessageResponseRequest::IssueRequest(std::error_code& ErrorCode) ZEN_ERROR("failed to send HTTP response (error: '{}'), request URL: {}"sv, SendResult, HttpReq->pRawUrl); - ErrorCode = MakeWin32ErrorCode(SendResult); + ErrorCode = MakeErrorCode(SendResult); } else { @@ -1231,7 +1231,7 @@ InitialRequestHandler::IssueRequest(std::error_code& ErrorCode) // CleanupHttpIoRequest(pIoRequest); - ErrorCode = MakeWin32ErrorCode(HttpApiResult); + ErrorCode = MakeErrorCode(HttpApiResult); ZEN_ERROR("HttpReceiveHttpRequest failed, error {}", ErrorCode.message()); -- cgit v1.2.3 From dd9aec560688547dfd60090436d843c76450bd62 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 27 Sep 2021 11:43:40 +0200 Subject: GetWindowsErrorAsString() -> GetSystemErrorAsString() --- zenhttp/httpsys.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'zenhttp/httpsys.cpp') diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index 2a50388e3..b08e39a8a 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -417,7 +417,7 @@ HttpMessageResponseRequest::HandleCompletion(ULONG IoResult, ULONG_PTR NumberOfB if (IoResult != NO_ERROR) { - ZEN_WARN("response aborted due to error: '{}'", GetWindowsErrorAsString(IoResult)); + ZEN_WARN("response aborted due to error: '{}'", GetSystemErrorAsString(IoResult)); // if one transmit failed there's really no need to go on return nullptr; @@ -554,7 +554,7 @@ HttpMessageResponseRequest::IssueRequest(std::error_code& ErrorCode) CancelThreadpoolIo(Iocp); ZEN_ERROR("failed to send HTTP response (error: '{}'), request URL: '{}', request id: {}", - GetWindowsErrorAsString(SendResult), + GetSystemErrorAsString(SendResult), HttpReq->pRawUrl, HttpReq->RequestId); -- cgit v1.2.3 From 4d06a410a2281564e90e8c4e3890d79084ed12ef Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 27 Sep 2021 11:46:13 +0200 Subject: Fixed httpsys Windows compilation error --- zenhttp/httpsys.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zenhttp/httpsys.cpp') diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index deaf95d5a..997491613 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -553,7 +553,7 @@ HttpMessageResponseRequest::IssueRequest(std::error_code& ErrorCode) CancelThreadpoolIo(Iocp); - ZEN_ERROR("failed to send HTTP response (error: '{}'), request URL: '{}'", GetWindowsErrorAsString(SendResult), HttpReq->pRawUrl); + ZEN_ERROR("failed to send HTTP response (error: '{}'), request URL: '{}'", GetErrorAsString(SendResult), HttpReq->pRawUrl); ErrorCode = MakeErrorCode(SendResult); } -- cgit v1.2.3 From 55e0ca966335fb87c136524197bfbb2346da37ac Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 27 Sep 2021 13:12:37 +0200 Subject: httpsys: added `if constexpr` to silence compiler warning on Windows --- zenhttp/httpsys.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zenhttp/httpsys.cpp') diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index 26bba5484..747e48bb3 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -42,7 +42,7 @@ UTF8_to_wstring(const char* in) if (((*in & 0xc0) != 0x80) && (codepoint <= 0x10ffff)) { - if (sizeof(wchar_t) > 2) + if constexpr (sizeof(wchar_t) > 2) { out.append(1, static_cast(codepoint)); } -- cgit v1.2.3 From 250c1ce9c9df36b05dcacb8b10c6330ce8bad4cb Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 27 Sep 2021 16:24:13 +0200 Subject: httpsys: Added HTTP_SEND_RESPONSE_FLAG_BUFFER_DATA to response calls which should improve overall performance (yet to be confirmed) Also added custom Server: header --- zenhttp/httpsys.cpp | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) (limited to 'zenhttp/httpsys.cpp') diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index 747e48bb3..f87d3c21d 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -465,7 +465,7 @@ HttpMessageResponseRequest::IssueRequest(std::error_code& ErrorCode) HttpSendHttpResponse function as well. */ - ULONG SendFlags = 0; + ULONG SendFlags = HTTP_SEND_RESPONSE_FLAG_BUFFER_DATA; if (m_RemainingChunkCount) { @@ -484,6 +484,23 @@ HttpMessageResponseRequest::IssueRequest(std::error_code& ErrorCode) HttpResponse.EntityChunkCount = USHORT(ThisRequestChunkCount); HttpResponse.pEntityChunks = m_HttpDataChunks.data() + ThisRequestChunkOffset; + // Server header + // + // By default this will also add a suffix " Microsoft-HTTPAPI/2.0" to this header + // + // This is controlled via a registry key 'DisableServerHeader', at: + // + // Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters + // + // Set DisableServerHeader to 1 to disable suffix, or 2 to disable the header altogether + // + // (reference https://docs.microsoft.com/en-us/archive/blogs/dsnotes/wswcf-remove-server-header) + // + + PHTTP_KNOWN_HEADER ServerHeader = &HttpResponse.Headers.KnownHeaders[HttpHeaderServer]; + ServerHeader->pRawValue = "Zen"; + ServerHeader->RawValueLength = (USHORT)3; + // Content-length header char ContentLengthString[32]; @@ -545,11 +562,21 @@ HttpMessageResponseRequest::IssueRequest(std::error_code& ErrorCode) ); } - if ((SendResult != NO_ERROR) // Synchronous completion, but the completion event will still be posted to IOCP - && (SendResult != ERROR_IO_PENDING) // Asynchronous completion - ) + if (SendResult == NO_ERROR) + { + // Synchronous completion, but the completion event will still be posted to IOCP + + ErrorCode.clear(); + } + else if (SendResult == ERROR_IO_PENDING) + { + // Asynchronous completion, a completion notification will be posted to IOCP + + ErrorCode.clear(); + } + else { - // Some error occurred, no completion will be posted + // An error occurred, no completion will be posted to IOCP CancelThreadpoolIo(Iocp); @@ -560,10 +587,6 @@ HttpMessageResponseRequest::IssueRequest(std::error_code& ErrorCode) ErrorCode = MakeErrorCode(SendResult); } - else - { - ErrorCode = {}; - } } /** @@ -1244,13 +1267,6 @@ InitialRequestHandler::IssueRequest(std::error_code& ErrorCode) { CancelThreadpoolIo(Iocp); - if (HttpApiResult == ERROR_MORE_DATA) - { - // ProcessReceiveAndPostResponse(pIoRequest, pServerContext->Io, ERROR_MORE_DATA); - } - - // CleanupHttpIoRequest(pIoRequest); - ErrorCode = MakeErrorCode(HttpApiResult); ZEN_ERROR("HttpReceiveHttpRequest failed, error {}", ErrorCode.message()); @@ -1258,7 +1274,7 @@ InitialRequestHandler::IssueRequest(std::error_code& ErrorCode) return; } - ErrorCode = std::error_code(); + ErrorCode.clear(); } HttpSysRequestHandler* -- cgit v1.2.3 From 0391fe7c9917ff03730e9c90b2c0559cbe215eeb Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 27 Sep 2021 17:16:30 +0200 Subject: clang-format --- zenhttp/httpsys.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'zenhttp/httpsys.cpp') diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index f87d3c21d..bccff24ab 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -487,11 +487,11 @@ HttpMessageResponseRequest::IssueRequest(std::error_code& ErrorCode) // Server header // // By default this will also add a suffix " Microsoft-HTTPAPI/2.0" to this header - // + // // This is controlled via a registry key 'DisableServerHeader', at: - // + // // Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters - // + // // Set DisableServerHeader to 1 to disable suffix, or 2 to disable the header altogether // // (reference https://docs.microsoft.com/en-us/archive/blogs/dsnotes/wswcf-remove-server-header) -- cgit v1.2.3