nghttpx: Fix the bug that forwarded query contains duplicated '?'
This change also fixes that bug that the multiple '/' at the start of request were not coalesced into one.
This commit is contained in:
parent
2eb7137e04
commit
01408209d8
|
@ -1550,6 +1550,8 @@ StringRef path_join(BlockAllocator &balloc, const StringRef &base_path,
|
|||
if (rel_path[0] == '/') {
|
||||
*p++ = '/';
|
||||
++first;
|
||||
for (; first != last && *first == '/'; ++first)
|
||||
;
|
||||
} else if (base_path.empty()) {
|
||||
*p++ = '/';
|
||||
} else {
|
||||
|
@ -1657,11 +1659,12 @@ StringRef rewrite_clean_path(BlockAllocator &balloc, const StringRef &src) {
|
|||
}
|
||||
// probably, not necessary most of the case, but just in case.
|
||||
auto fragment = std::find(std::begin(src), std::end(src), '#');
|
||||
auto query = std::find(std::begin(src), fragment, '?');
|
||||
auto raw_query = std::find(std::begin(src), fragment, '?');
|
||||
auto query = raw_query;
|
||||
if (query != fragment) {
|
||||
++query;
|
||||
}
|
||||
return normalize_path(balloc, StringRef{std::begin(src), query},
|
||||
return normalize_path(balloc, StringRef{std::begin(src), raw_query},
|
||||
StringRef{query, fragment});
|
||||
}
|
||||
|
||||
|
|
|
@ -817,6 +817,15 @@ void test_http2_path_join(void) {
|
|||
auto rel = StringRef{};
|
||||
CU_ASSERT("/?r" == http2::path_join(base, baseq, rel, StringRef{}));
|
||||
}
|
||||
{
|
||||
// path starts with multiple '/'s.
|
||||
auto base = StringRef{};
|
||||
auto baseq = StringRef{};
|
||||
auto rel = StringRef::from_lit("//alpha//bravo");
|
||||
auto relq = StringRef::from_lit("charlie");
|
||||
CU_ASSERT("/alpha/bravo?charlie" ==
|
||||
http2::path_join(base, baseq, rel, relq));
|
||||
}
|
||||
}
|
||||
|
||||
void test_http2_normalize_path(void) {
|
||||
|
@ -870,6 +879,10 @@ void test_http2_rewrite_clean_path(void) {
|
|||
http2::rewrite_clean_path(balloc, StringRef::from_lit("alpha%3a")));
|
||||
|
||||
CU_ASSERT("" == http2::rewrite_clean_path(balloc, StringRef{}));
|
||||
|
||||
CU_ASSERT(
|
||||
"/alpha?bravo" ==
|
||||
http2::rewrite_clean_path(balloc, StringRef::from_lit("//alpha?bravo")));
|
||||
}
|
||||
|
||||
void test_http2_get_pure_path_component(void) {
|
||||
|
|
Loading…
Reference in New Issue