src: Don't push if Link header field includes nopush
This commit is contained in:
parent
5da38b22c0
commit
9afc017532
33
src/http2.cc
33
src/http2.cc
|
@ -864,6 +864,29 @@ bool check_link_param_empty(const char *first, const char *last,
|
|||
}
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
// Returns true if link-param consists of only parmname, and it
|
||||
// matches string [pat, pat + patlen).
|
||||
bool check_link_param_without_value(const char *first, const char *last,
|
||||
const char *pat, size_t patlen) {
|
||||
if (first + patlen > last) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (first + patlen == last) {
|
||||
return std::equal(pat, pat + patlen, first, util::CaseCmp());
|
||||
}
|
||||
|
||||
switch (*(first + patlen)) {
|
||||
case ';':
|
||||
case ',':
|
||||
return std::equal(pat, pat + patlen, first, util::CaseCmp());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
std::pair<LinkHeader, const char *>
|
||||
parse_next_link_header_once(const char *first, const char *last) {
|
||||
|
@ -900,6 +923,7 @@ parse_next_link_header_once(const char *first, const char *last) {
|
|||
}
|
||||
// we expect link-param
|
||||
|
||||
if (!ign) {
|
||||
// rel can take several relations using quoted form.
|
||||
static constexpr char PLP[] = "rel=\"";
|
||||
static constexpr size_t PLPLEN = sizeof(PLP) - 1;
|
||||
|
@ -995,6 +1019,15 @@ parse_next_link_header_once(const char *first, const char *last) {
|
|||
ign = true;
|
||||
}
|
||||
|
||||
// reject URI if we have nopush attribute.
|
||||
static constexpr char NOPUSH[] = "nopush";
|
||||
static constexpr size_t NOPUSHLEN = str_size(NOPUSH);
|
||||
if (!ign &&
|
||||
check_link_param_without_value(first, last, NOPUSH, NOPUSHLEN)) {
|
||||
ign = true;
|
||||
}
|
||||
}
|
||||
|
||||
auto param_first = first;
|
||||
for (; first != last;) {
|
||||
if (util::in_attr_char(*first)) {
|
||||
|
|
|
@ -625,6 +625,38 @@ void test_http2_parse_link_header(void) {
|
|||
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);
|
||||
}
|
||||
{
|
||||
// nopush at the end of input
|
||||
constexpr char s[] = "<url>; rel=preload; nopush";
|
||||
auto res = http2::parse_link_header(s, str_size(s));
|
||||
CU_ASSERT(0 == res.size());
|
||||
}
|
||||
{
|
||||
// nopush followed by ';'
|
||||
constexpr char s[] = "<url>; rel=preload; nopush; foo";
|
||||
auto res = http2::parse_link_header(s, str_size(s));
|
||||
CU_ASSERT(0 == res.size());
|
||||
}
|
||||
{
|
||||
// nopush followed by ','
|
||||
constexpr char s[] = "<url>; nopush; rel=preload";
|
||||
auto res = http2::parse_link_header(s, str_size(s));
|
||||
CU_ASSERT(0 == res.size());
|
||||
}
|
||||
{
|
||||
// string whose prefix is nopush
|
||||
constexpr char s[] = "<url>; nopushyes; rel=preload";
|
||||
auto res = http2::parse_link_header(s, str_size(s));
|
||||
CU_ASSERT(1 == res.size());
|
||||
CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri);
|
||||
}
|
||||
{
|
||||
// rel=preload twice
|
||||
constexpr char s[] = "<url>; rel=preload; rel=preload";
|
||||
auto res = http2::parse_link_header(s, str_size(s));
|
||||
CU_ASSERT(1 == res.size());
|
||||
CU_ASSERT(std::make_pair(&s[1], &s[4]) == res[0].uri);
|
||||
}
|
||||
}
|
||||
|
||||
void test_http2_path_join(void) {
|
||||
|
|
Loading…
Reference in New Issue