diff options
| author | Stefan Boberg <[email protected]> | 2021-10-04 17:10:00 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-04 17:10:00 +0200 |
| commit | 6852966e20c122957cd902c5486079249429f610 (patch) | |
| tree | 05b082210562369b33e6f459a6d169ef142b1bbd /zenhttp/httpsys.cpp | |
| parent | zenserver: Changed initialization flow (diff) | |
| download | zen-6852966e20c122957cd902c5486079249429f610.tar.xz zen-6852966e20c122957cd902c5486079249429f610.zip | |
http: strip any known content-type suffixes from URI before passing it to a service
Diffstat (limited to 'zenhttp/httpsys.cpp')
| -rw-r--r-- | zenhttp/httpsys.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index fedaf282e..de3069bb8 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -1091,29 +1091,34 @@ HttpSysServerRequest::HttpSysServerRequest(HttpSysTransaction& Tx, HttpService& if (AbsPathLength >= PrefixLength) { // We convert the URI immediately because most of the code involved prefers to deal - // with utf8. This has some performance impact which I'd prefer to avoid but for now - // we just have to live with it + // 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)}, m_UriUtf8); - std::string_view Uri8{m_UriUtf8}; + std::string_view UriSuffix8{m_UriUtf8}; - const size_t LastComponentIndex = Uri8.find_last_of('/'); + const size_t LastComponentIndex = UriSuffix8.find_last_of('/'); if (LastComponentIndex != std::string_view::npos) { - Uri8.remove_prefix(LastComponentIndex); + UriSuffix8.remove_prefix(LastComponentIndex); } - const size_t LastDotIndex = Uri8.find_last_of('.'); + const size_t LastDotIndex = UriSuffix8.find_last_of('.'); if (LastDotIndex != std::string_view::npos) { - Uri8.remove_prefix(LastDotIndex + 1); - } + UriSuffix8.remove_prefix(LastDotIndex + 1); + + AcceptContentType = ParseContentType(UriSuffix8); - AcceptContentType = ParseContentType(Uri8); + if (AcceptContentType != HttpContentType::kUnknownContentType) + { + m_UriUtf8.RemoveSuffix(uint32_t(m_UriUtf8.Size() - LastComponentIndex - LastDotIndex - 1)); + } + } } else { |