diff options
| author | Stefan Boberg <[email protected]> | 2021-10-03 21:40:20 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-03 21:40:20 +0200 |
| commit | 132c476c82e82ed7978e82067c9159aaeebbd36f (patch) | |
| tree | ded8d61005361a7d9feb7e5a1aa1153e79d98839 /zenhttp/httpsys.cpp | |
| parent | Merge branch 'main' of https://github.com/EpicGames/zen (diff) | |
| parent | http: Moved logic for body suppression to a more central location (diff) | |
| download | zen-132c476c82e82ed7978e82067c9159aaeebbd36f.tar.xz zen-132c476c82e82ed7978e82067c9159aaeebbd36f.zip | |
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'zenhttp/httpsys.cpp')
| -rw-r--r-- | zenhttp/httpsys.cpp | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index 9b2e7f832..fedaf282e 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -1086,6 +1086,8 @@ HttpSysServerRequest::HttpSysServerRequest(HttpSysTransaction& Tx, HttpService& const int PrefixLength = Service.UriPrefixLength(); const int AbsPathLength = HttpRequestPtr->CookedUrl.AbsPathLength / sizeof(char16_t); + HttpContentType AcceptContentType = HttpContentType::kUnknownContentType; + if (AbsPathLength >= PrefixLength) { // We convert the URI immediately because most of the code involved prefers to deal @@ -1094,15 +1096,33 @@ HttpSysServerRequest::HttpSysServerRequest(HttpSysTransaction& Tx, HttpService& WideToUtf8({(char16_t*)HttpRequestPtr->CookedUrl.pAbsPath + PrefixLength, gsl::narrow<size_t>(AbsPathLength - PrefixLength)}, m_UriUtf8); + + std::string_view Uri8{m_UriUtf8}; + + const size_t LastComponentIndex = Uri8.find_last_of('/'); + + if (LastComponentIndex != std::string_view::npos) + { + Uri8.remove_prefix(LastComponentIndex); + } + + const size_t LastDotIndex = Uri8.find_last_of('.'); + + if (LastDotIndex != std::string_view::npos) + { + Uri8.remove_prefix(LastDotIndex + 1); + } + + AcceptContentType = ParseContentType(Uri8); } else { m_UriUtf8.Reset(); } - if (auto QueryStringLength = HttpRequestPtr->CookedUrl.QueryStringLength) + if (uint16_t QueryStringLength = HttpRequestPtr->CookedUrl.QueryStringLength) { - --QueryStringLength; + --QueryStringLength; // We skip the leading question mark WideToUtf8({(char16_t*)(HttpRequestPtr->CookedUrl.pQueryString) + 1, QueryStringLength / sizeof(char16_t)}, m_QueryStringUtf8); } @@ -1114,7 +1134,23 @@ HttpSysServerRequest::HttpSysServerRequest(HttpSysTransaction& Tx, HttpService& m_Verb = TranslateHttpVerb(HttpRequestPtr->Verb); m_ContentLength = GetContentLength(HttpRequestPtr); m_ContentType = GetContentType(HttpRequestPtr); - m_AcceptType = GetAcceptType(HttpRequestPtr); + + // It an explicit content type extension was specified then we'll use that over any + // Accept: header value that may be present + + if (AcceptContentType != HttpContentType::kUnknownContentType) + { + m_AcceptType = AcceptContentType; + } + else + { + m_AcceptType = GetAcceptType(HttpRequestPtr); + } + + if (m_Verb == HttpVerb::kHead) + { + SetSuppressResponseBody(); + } } Oid |