diff options
Diffstat (limited to 'src/zenhttp')
| -rw-r--r-- | src/zenhttp/httpserver.cpp | 34 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpserver.h | 2 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp index dcbeac907..adb3128bf 100644 --- a/src/zenhttp/httpserver.cpp +++ b/src/zenhttp/httpserver.cpp @@ -530,6 +530,40 @@ HttpServerRequest::WriteResponse(HttpResponseCode ResponseCode, HttpContentType WriteResponse(ResponseCode, ContentType, Buffers); } +std::string +HttpServerRequest::Decode(std::string_view PercentEncodedString) +{ + size_t Length = PercentEncodedString.length(); + std::string Decoded; + Decoded.reserve(Length); + size_t Offset = 0; + while (Offset < Length) + { + char C = PercentEncodedString[Offset]; + if (C == '%' && (Offset <= (Length - 3))) + { + std::string_view CharHash(&PercentEncodedString[Offset + 1], 2); + uint8_t DecodedChar = 0; + if (ParseHexBytes(CharHash, &DecodedChar)) + { + Decoded.push_back((char)DecodedChar); + Offset += 3; + } + else + { + Decoded.push_back(C); + Offset++; + } + } + else + { + Decoded.push_back(C); + Offset++; + } + } + return Decoded; +} + HttpServerRequest::QueryParams HttpServerRequest::GetQueryParams() { diff --git a/src/zenhttp/include/zenhttp/httpserver.h b/src/zenhttp/include/zenhttp/httpserver.h index 1089dd221..7b87cb84b 100644 --- a/src/zenhttp/include/zenhttp/httpserver.h +++ b/src/zenhttp/include/zenhttp/httpserver.h @@ -62,6 +62,8 @@ public: } }; + static std::string Decode(std::string_view PercentEncodedString); + virtual bool TryGetRanges(HttpRanges&) { return false; } QueryParams GetQueryParams(); |