diff options
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() |