src: Use case-insensitive match when parsing Link header field
This commit is contained in:
parent
7fa62c9904
commit
07fdaaba45
14
src/http2.cc
14
src/http2.cc
|
@ -771,7 +771,7 @@ parse_next_link_header_once(const char *first, const char *last) {
|
||||||
static const char PLT[] = "preload";
|
static const char PLT[] = "preload";
|
||||||
static const size_t PLTLEN = sizeof(PLT) - 1;
|
static const size_t PLTLEN = sizeof(PLT) - 1;
|
||||||
if (first + PLPLEN < last && *(first + PLPLEN - 1) == '"' &&
|
if (first + PLPLEN < last && *(first + PLPLEN - 1) == '"' &&
|
||||||
std::equal(PLP, PLP + PLPLEN, first)) {
|
std::equal(PLP, PLP + PLPLEN, first, util::CaseCmp())) {
|
||||||
// we have to search preload in whitespace separated list:
|
// we have to search preload in whitespace separated list:
|
||||||
// rel="preload something http://example.org/foo"
|
// rel="preload something http://example.org/foo"
|
||||||
first += PLPLEN;
|
first += PLPLEN;
|
||||||
|
@ -786,8 +786,8 @@ parse_next_link_header_once(const char *first, const char *last) {
|
||||||
return {{{nullptr, nullptr}}, last};
|
return {{{nullptr, nullptr}}, last};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ok && start + PLTLEN == first && *(start + PLTLEN - 1) == 'd' &&
|
if (!ok && start + PLTLEN == first &&
|
||||||
std::equal(PLT, PLT + PLTLEN, start)) {
|
std::equal(PLT, PLT + PLTLEN, start, util::CaseCmp())) {
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -817,7 +817,7 @@ parse_next_link_header_once(const char *first, const char *last) {
|
||||||
static const char PL[] = "rel=preload";
|
static const char PL[] = "rel=preload";
|
||||||
static const size_t PLLEN = sizeof(PL) - 1;
|
static const size_t PLLEN = sizeof(PL) - 1;
|
||||||
if (first + PLLEN == last) {
|
if (first + PLLEN == last) {
|
||||||
if (std::equal(PL, PL + PLLEN, first)) {
|
if (std::equal(PL, PL + PLLEN, first, util::CaseCmp())) {
|
||||||
ok = true;
|
ok = true;
|
||||||
// this is the end of sequence
|
// this is the end of sequence
|
||||||
return {{{url_first, url_last}}, last};
|
return {{{url_first, url_last}}, last};
|
||||||
|
@ -825,7 +825,7 @@ parse_next_link_header_once(const char *first, const char *last) {
|
||||||
} else if (first + PLLEN + 1 <= last) {
|
} else if (first + PLLEN + 1 <= last) {
|
||||||
switch (*(first + PLLEN)) {
|
switch (*(first + PLLEN)) {
|
||||||
case ',':
|
case ',':
|
||||||
if (!std::equal(PL, PL + PLLEN, first)) {
|
if (!std::equal(PL, PL + PLLEN, first, util::CaseCmp())) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ok = true;
|
ok = true;
|
||||||
|
@ -833,7 +833,7 @@ parse_next_link_header_once(const char *first, const char *last) {
|
||||||
first += PLLEN + 1;
|
first += PLLEN + 1;
|
||||||
return {{{url_first, url_last}}, first};
|
return {{{url_first, url_last}}, first};
|
||||||
case ';':
|
case ';':
|
||||||
if (!std::equal(PL, PL + PLLEN, first)) {
|
if (!std::equal(PL, PL + PLLEN, first, util::CaseCmp())) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ok = true;
|
ok = true;
|
||||||
|
@ -847,7 +847,7 @@ parse_next_link_header_once(const char *first, const char *last) {
|
||||||
static const char ANCHOR[] = "anchor=";
|
static const char ANCHOR[] = "anchor=";
|
||||||
static const size_t ANCHORLEN = sizeof(ANCHOR) - 1;
|
static const size_t ANCHORLEN = sizeof(ANCHOR) - 1;
|
||||||
if (!ign && first + ANCHORLEN <= last) {
|
if (!ign && first + ANCHORLEN <= last) {
|
||||||
if (std::equal(ANCHOR, ANCHOR + ANCHORLEN, first)) {
|
if (std::equal(ANCHOR, ANCHOR + ANCHORLEN, first, util::CaseCmp())) {
|
||||||
// we only accept URI if anchor="" here.
|
// we only accept URI if anchor="" here.
|
||||||
if (first + ANCHORLEN + 2 <= last) {
|
if (first + ANCHORLEN + 2 <= last) {
|
||||||
if (*(first + ANCHORLEN) != '"' || *(first + ANCHORLEN + 1) != '"') {
|
if (*(first + ANCHORLEN) != '"' || *(first + ANCHORLEN + 1) != '"') {
|
||||||
|
|
|
@ -627,6 +627,15 @@ void test_http2_parse_link_header(void) {
|
||||||
CU_ASSERT(1 == res.size());
|
CU_ASSERT(1 == res.size());
|
||||||
CU_ASSERT(std::make_pair(&s[36], &s[39]) == res[0].uri);
|
CU_ASSERT(std::make_pair(&s[36], &s[39]) == res[0].uri);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
// case-insensitive match
|
||||||
|
const char s[] = R"(<url>; rel=preload; ANCHOR="#foo", <url>; )"
|
||||||
|
R"(REL=PRELOAD, <url>; REL="foo PRELOAD bar")";
|
||||||
|
auto res = http2::parse_link_header(s, sizeof(s) - 1);
|
||||||
|
CU_ASSERT(2 == res.size());
|
||||||
|
CU_ASSERT(std::make_pair(&s[36], &s[39]) == res[0].uri);
|
||||||
|
CU_ASSERT(std::make_pair(&s[42 + 14], &s[42 + 17]) == res[1].uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_http2_path_join(void) {
|
void test_http2_path_join(void) {
|
||||||
|
|
Loading…
Reference in New Issue