aboutsummaryrefslogtreecommitdiff
path: root/zenhttp/httpasio.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-12-08 09:04:04 +0100
committerMartin Ridgers <[email protected]>2021-12-08 09:04:04 +0100
commit1037aa9edc9b88d9c59fdf2d2531ac265b571b3c (patch)
tree805f277f60b1eba7de8b78ae209d7464bcedd398 /zenhttp/httpasio.cpp
parentImplement zen/internalfile for POSIX platforms (diff)
parentUse 'Platform' instead of 'OSFamily' for Horde condition (diff)
downloadzen-1037aa9edc9b88d9c59fdf2d2531ac265b571b3c.tar.xz
zen-1037aa9edc9b88d9c59fdf2d2531ac265b571b3c.zip
Merged main
Diffstat (limited to 'zenhttp/httpasio.cpp')
-rw-r--r--zenhttp/httpasio.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/zenhttp/httpasio.cpp b/zenhttp/httpasio.cpp
index e2b9262ff..131c4513f 100644
--- a/zenhttp/httpasio.cpp
+++ b/zenhttp/httpasio.cpp
@@ -124,7 +124,7 @@ struct HttpRequest
HttpVerb RequestVerb() const { return m_RequestVerb; }
bool IsKeepAlive() const { return m_KeepAlive; }
- std::string_view Url() const { return std::string_view(m_Url, m_UrlLength); }
+ std::string_view Url() const { return m_NormalizedUrl.empty() ? std::string_view(m_Url, m_UrlLength) : m_NormalizedUrl; }
std::string_view QueryString() const { return std::string_view(m_QueryString, m_QueryLength); }
IoBuffer Body() { return m_BodyBuffer; }
@@ -181,6 +181,7 @@ private:
uint64_t m_BodyPosition = 0;
http_parser m_Parser;
char m_HeaderBuffer[1024];
+ std::string m_NormalizedUrl;
void AppendInputBytes(const char* Data, size_t Bytes);
void AppendCurrentHeader();
@@ -752,6 +753,37 @@ HttpRequest::TerminateConnection()
m_Connection.TerminateConnection();
}
+static void
+NormalizeUrlPath(const char* Url, size_t UrlLength, std::string& NormalizedUrl)
+{
+ bool LastCharWasSeparator = false;
+ for (std::string_view::size_type UrlIndex = 0; UrlIndex < UrlLength; ++UrlIndex)
+ {
+ const char UrlChar = Url[UrlIndex];
+ const bool IsSeparator = (UrlChar == '/');
+
+ if (IsSeparator && LastCharWasSeparator)
+ {
+ if (NormalizedUrl.empty())
+ {
+ NormalizedUrl.reserve(UrlLength);
+ NormalizedUrl.append(Url, UrlIndex);
+ }
+
+ if (!LastCharWasSeparator)
+ {
+ NormalizedUrl.push_back('/');
+ }
+ }
+ else if (!NormalizedUrl.empty())
+ {
+ NormalizedUrl.push_back(UrlChar);
+ }
+
+ LastCharWasSeparator = IsSeparator;
+ }
+}
+
int
HttpRequest::OnHeadersComplete()
{
@@ -818,6 +850,9 @@ HttpRequest::OnHeadersComplete()
m_QueryLength = Url.size() - QuerySplit - 1;
}
+ NormalizeUrlPath(m_Url, m_UrlLength, m_NormalizedUrl);
+
+
return 0;
}
@@ -858,6 +893,7 @@ HttpRequest::ResetState()
m_BodyBuffer = {};
m_BodyPosition = 0;
m_Headers.clear();
+ m_NormalizedUrl.clear();
}
int