diff options
| author | Stefan Boberg <[email protected]> | 2021-10-15 11:47:07 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-15 11:47:07 +0200 |
| commit | 7ffdfcff4f0c5b7ab5699a448353a21532563b80 (patch) | |
| tree | 683a3a38abb74cf509795d866ac667b65f57c2f0 /zenhttp/httpasio.cpp | |
| parent | clang-format (diff) | |
| download | zen-7ffdfcff4f0c5b7ab5699a448353a21532563b80.tar.xz zen-7ffdfcff4f0c5b7ab5699a448353a21532563b80.zip | |
httpasio: Implemented support for specifying accept type via url suffix
Diffstat (limited to 'zenhttp/httpasio.cpp')
| -rw-r--r-- | zenhttp/httpasio.cpp | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/zenhttp/httpasio.cpp b/zenhttp/httpasio.cpp index 1f049b0c1..12fbdb61e 100644 --- a/zenhttp/httpasio.cpp +++ b/zenhttp/httpasio.cpp @@ -930,12 +930,46 @@ HttpAsioServerRequest::HttpAsioServerRequest(asio_http::HttpRequest& Request, Ht m_ContentLength = Request.Body().Size(); m_ContentType = Request.ContentType(); + HttpContentType AcceptContentType = HttpContentType::kUnknownContentType; + + // Parse any extension, to allow requesting a particular response encoding via the URL + + { + std::string_view UriSuffix8{m_Uri}; + + const size_t LastComponentIndex = UriSuffix8.find_last_of('/'); + + if (LastComponentIndex != std::string_view::npos) + { + UriSuffix8.remove_prefix(LastComponentIndex); + } + + const size_t LastDotIndex = UriSuffix8.find_last_of('.'); + + if (LastDotIndex != std::string_view::npos) + { + UriSuffix8.remove_prefix(LastDotIndex + 1); + + AcceptContentType = ParseContentType(UriSuffix8); + + if (AcceptContentType != HttpContentType::kUnknownContentType) + { + m_Uri.remove_suffix(uint32_t(m_Uri.size() - LastComponentIndex - LastDotIndex - 1)); + } + } + } + // It an explicit content type extension was specified then we'll use that over any // Accept: header value that may be present - // - // TODO! - m_AcceptType = Request.AcceptType(); + if (AcceptContentType != HttpContentType::kUnknownContentType) + { + m_AcceptType = AcceptContentType; + } + else + { + m_AcceptType = Request.AcceptType(); + } } HttpAsioServerRequest::~HttpAsioServerRequest() |