aboutsummaryrefslogtreecommitdiff
path: root/zenhttp
diff options
context:
space:
mode:
Diffstat (limited to 'zenhttp')
-rw-r--r--zenhttp/httpasio.cpp58
1 files changed, 32 insertions, 26 deletions
diff --git a/zenhttp/httpasio.cpp b/zenhttp/httpasio.cpp
index ecca05e08..9a23a25ef 100644
--- a/zenhttp/httpasio.cpp
+++ b/zenhttp/httpasio.cpp
@@ -751,6 +751,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()
{
@@ -817,32 +848,7 @@ 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;
- }
+ NormalizeUrlPath(m_Url, m_UrlLength, m_NormalizedUrl);
return 0;