src: Refactor parse_next_link_header_once
This commit is contained in:
parent
9e723b6b1d
commit
4d47c31ebe
20
src/http2.cc
20
src/http2.cc
|
@ -759,28 +759,34 @@ parse_next_link_header_once(const char *first, const char *last) {
|
||||||
// we are only interested in rel=preload parameter. Others are
|
// we are only interested in rel=preload parameter. Others are
|
||||||
// simply skipped.
|
// simply skipped.
|
||||||
static const char PL[] = "rel=preload";
|
static const char PL[] = "rel=preload";
|
||||||
if (last - first >= sizeof(PL) - 1) {
|
static const size_t PLLEN = sizeof(PL) - 1;
|
||||||
if (memcmp(PL, first, sizeof(PL) - 1) == 0) {
|
if (first + PLLEN == last) {
|
||||||
if (first + sizeof(PL) - 1 == last) {
|
if (std::equal(PL, PL + PLLEN, first)) {
|
||||||
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};
|
||||||
}
|
}
|
||||||
switch (*(first + sizeof(PL) - 1)) {
|
} else if (first + PLLEN + 1 <= last) {
|
||||||
|
switch (*(first + PLLEN)) {
|
||||||
case ',':
|
case ',':
|
||||||
|
if (!std::equal(PL, PL + PLLEN, first)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
ok = true;
|
ok = true;
|
||||||
// skip including ','
|
// skip including ','
|
||||||
first += sizeof(PL);
|
first += PLLEN + 1;
|
||||||
return {{{url_first, url_last}}, first};
|
return {{{url_first, url_last}}, first};
|
||||||
case ';':
|
case ';':
|
||||||
|
if (!std::equal(PL, PL + PLLEN, first)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
ok = true;
|
ok = true;
|
||||||
// skip including ';'
|
// skip including ';'
|
||||||
first += sizeof(PL);
|
first += PLLEN + 1;
|
||||||
// continue parse next link-param
|
// continue parse next link-param
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
auto param_first = first;
|
auto param_first = first;
|
||||||
for (; first != last;) {
|
for (; first != last;) {
|
||||||
if (util::in_attr_char(*first)) {
|
if (util::in_attr_char(*first)) {
|
||||||
|
|
|
@ -479,6 +479,12 @@ void test_http2_parse_link_header(void) {
|
||||||
CU_ASSERT(1 == res.size());
|
CU_ASSERT(1 == res.size());
|
||||||
CU_ASSERT(std::make_pair(&s[3], &s[6]) == res[0].uri);
|
CU_ASSERT(std::make_pair(&s[3], &s[6]) == res[0].uri);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
// preload is a prefix of bogus rel parameter value
|
||||||
|
const char s[] = "<url>; rel=preloadx";
|
||||||
|
auto res = http2::parse_link_header(s, sizeof(s) - 1);
|
||||||
|
CU_ASSERT(0 == res.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_http2_path_join(void) {
|
void test_http2_path_join(void) {
|
||||||
|
|
Loading…
Reference in New Issue