From d3dbaed60a152a6f9333d3ec6b23f0d1849db11a Mon Sep 17 00:00:00 2001 From: Yoshihiro Hokazono <47231909+hokacci@users.noreply.github.com> Date: Fri, 11 Aug 2023 16:20:00 +0900 Subject: [PATCH] Recognize URI in request lines (#1720) --- lib/src/HttpRequestParser.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/src/HttpRequestParser.cc b/lib/src/HttpRequestParser.cc index 1b02985d..b3f76cd6 100644 --- a/lib/src/HttpRequestParser.cc +++ b/lib/src/HttpRequestParser.cc @@ -56,15 +56,25 @@ bool HttpRequestParser::processRequestLine(const char *begin, const char *end) const char *space = std::find(start, end, ' '); if (space != end) { - const char *question = std::find(start, space, '?'); - if (question != space) + const char *slash = std::find(start, space, '/'); + if (slash != start && slash + 1 < space && *(slash + 1) == '/') { - request_->setPath(start, question); - request_->setQuery(question + 1, space); + // scheme precedents + slash = std::find(slash + 2, space, '/'); + } + const char *question = std::find(slash, space, '?'); + if (slash != space) + { + request_->setPath(slash, question); } else { - request_->setPath(start, space); + // An empty abs_path is equivalent to an abs_path of "/" + request_->setPath("/"); + } + if (question != space) + { + request_->setQuery(question + 1, space); } start = space + 1; succeed = end - start == 8 && std::equal(start, end - 1, "HTTP/1.");