diff options
| author | Dan Engelbrecht <[email protected]> | 2023-08-09 11:02:28 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-08-09 11:02:28 +0200 |
| commit | 4a0e5a7cc9f199e8c8ca3794d16d92aa130bd644 (patch) | |
| tree | d685505bc6b8700ef38fe895a644cb83e3df8376 /src/zenhttp/httpasio.cpp | |
| parent | use streaming read for PutCompressedBlob if source is single file (#338) (diff) | |
| download | zen-4a0e5a7cc9f199e8c8ca3794d16d92aa130bd644.tar.xz zen-4a0e5a7cc9f199e8c8ca3794d16d92aa130bd644.zip | |
handle exception in asio header parsing (#348)
* make sure we return an error code instead of throwing exception if header parsing fails
* changelog
Diffstat (limited to 'src/zenhttp/httpasio.cpp')
| -rw-r--r-- | src/zenhttp/httpasio.cpp | 107 |
1 files changed, 57 insertions, 50 deletions
diff --git a/src/zenhttp/httpasio.cpp b/src/zenhttp/httpasio.cpp index 20b62e225..e12125bcc 100644 --- a/src/zenhttp/httpasio.cpp +++ b/src/zenhttp/httpasio.cpp @@ -839,75 +839,82 @@ NormalizeUrlPath(const char* Url, size_t UrlLength, std::string& NormalizedUrl) int HttpRequest::OnHeadersComplete() { - if (m_CurrentHeaderValueLength) + try { - AppendCurrentHeader(); - } + if (m_CurrentHeaderValueLength) + { + AppendCurrentHeader(); + } - if (m_ContentLengthHeaderIndex >= 0) - { - std::string_view& Value = m_Headers[m_ContentLengthHeaderIndex].Value; - uint64_t ContentLength = 0; - std::from_chars(Value.data(), Value.data() + Value.size(), ContentLength); + m_KeepAlive = !!http_should_keep_alive(&m_Parser); - if (ContentLength) + switch (m_Parser.method) { - m_BodyBuffer = IoBuffer(ContentLength); - } + case HTTP_GET: + m_RequestVerb = HttpVerb::kGet; + break; - m_BodyBuffer.SetContentType(ContentType()); + case HTTP_POST: + m_RequestVerb = HttpVerb::kPost; + break; - m_BodyPosition = 0; - } + case HTTP_PUT: + m_RequestVerb = HttpVerb::kPut; + break; - m_KeepAlive = !!http_should_keep_alive(&m_Parser); + case HTTP_DELETE: + m_RequestVerb = HttpVerb::kDelete; + break; - switch (m_Parser.method) - { - case HTTP_GET: - m_RequestVerb = HttpVerb::kGet; - break; + case HTTP_HEAD: + m_RequestVerb = HttpVerb::kHead; + break; - case HTTP_POST: - m_RequestVerb = HttpVerb::kPost; - break; + case HTTP_COPY: + m_RequestVerb = HttpVerb::kCopy; + break; - case HTTP_PUT: - m_RequestVerb = HttpVerb::kPut; - break; + case HTTP_OPTIONS: + m_RequestVerb = HttpVerb::kOptions; + break; - case HTTP_DELETE: - m_RequestVerb = HttpVerb::kDelete; - break; + default: + ZEN_WARN("invalid HTTP method: '{}'", http_method_str((http_method)m_Parser.method)); + break; + } - case HTTP_HEAD: - m_RequestVerb = HttpVerb::kHead; - break; + std::string_view Url(m_Url, m_UrlLength); - case HTTP_COPY: - m_RequestVerb = HttpVerb::kCopy; - break; + if (auto QuerySplit = Url.find_first_of('?'); QuerySplit != std::string_view::npos) + { + m_UrlLength = QuerySplit; + m_QueryString = m_Url + QuerySplit + 1; + m_QueryLength = Url.size() - QuerySplit - 1; + } - case HTTP_OPTIONS: - m_RequestVerb = HttpVerb::kOptions; - break; + NormalizeUrlPath(m_Url, m_UrlLength, m_NormalizedUrl); - default: - ZEN_WARN("invalid HTTP method: '{}'", http_method_str((http_method)m_Parser.method)); - break; - } + if (m_ContentLengthHeaderIndex >= 0) + { + std::string_view& Value = m_Headers[m_ContentLengthHeaderIndex].Value; + uint64_t ContentLength = 0; + std::from_chars(Value.data(), Value.data() + Value.size(), ContentLength); - std::string_view Url(m_Url, m_UrlLength); + if (ContentLength) + { + m_BodyBuffer = IoBuffer(ContentLength); + } - if (auto QuerySplit = Url.find_first_of('?'); QuerySplit != std::string_view::npos) + m_BodyBuffer.SetContentType(ContentType()); + + m_BodyPosition = 0; + } + } + catch (const std::exception& Ex) { - m_UrlLength = QuerySplit; - m_QueryString = m_Url + QuerySplit + 1; - m_QueryLength = Url.size() - QuerySplit - 1; + ZEN_WARN("HttpRequest::OnHeadersComplete failed. Reason '{}'", Ex.what()); + return -1; } - - NormalizeUrlPath(m_Url, m_UrlLength, m_NormalizedUrl); - return 0; } |