aboutsummaryrefslogtreecommitdiff
path: root/zenhttp/httpasio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zenhttp/httpasio.cpp')
-rw-r--r--zenhttp/httpasio.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/zenhttp/httpasio.cpp b/zenhttp/httpasio.cpp
index b9db108db..ecca05e08 100644
--- a/zenhttp/httpasio.cpp
+++ b/zenhttp/httpasio.cpp
@@ -122,7 +122,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; }
@@ -179,6 +179,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();
@@ -816,6 +817,34 @@ HttpRequest::OnHeadersComplete()
m_QueryLength = Url.size() - QuerySplit - 1;
}
+ bool bLastCharWasSeparator = false;
+ for (std::string_view::size_type UrlIndex = 0; UrlIndex < m_UrlLength; ++UrlIndex)
+ {
+ char UrlChar = m_Url[UrlIndex];
+ bool bIsSeparator = (UrlChar == '\\') || (UrlChar == '/');
+
+ if ((UrlChar == '\\') || (bIsSeparator && bLastCharWasSeparator))
+ {
+ if (m_NormalizedUrl.empty())
+ {
+ m_NormalizedUrl.reserve(m_UrlLength);
+ m_NormalizedUrl.append(m_Url, UrlIndex);
+ }
+
+ if (!bLastCharWasSeparator)
+ {
+ m_NormalizedUrl.push_back('/');
+ }
+ }
+ else if (!m_NormalizedUrl.empty())
+ {
+ m_NormalizedUrl.push_back(UrlChar);
+ }
+
+ bLastCharWasSeparator = bIsSeparator;
+ }
+
+
return 0;
}
@@ -856,6 +885,7 @@ HttpRequest::ResetState()
m_BodyBuffer = {};
m_BodyPosition = 0;
m_Headers.clear();
+ m_NormalizedUrl.clear();
}
int