Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
9afc0175
Commit
9afc0175
authored
Mar 03, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src: Don't push if Link header field includes nopush
parent
5da38b22
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
148 additions
and
83 deletions
+148
-83
src/http2.cc
src/http2.cc
+116
-83
src/http2_test.cc
src/http2_test.cc
+32
-0
No files found.
src/http2.cc
View file @
9afc0175
...
...
@@ -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,99 +923,109 @@ parse_next_link_header_once(const char *first, const char *last) {
}
// we expect link-param
// rel can take several relations using quoted form.
static
constexpr
char
PLP
[]
=
"rel=
\"
"
;
static
constexpr
size_t
PLPLEN
=
sizeof
(
PLP
)
-
1
;
static
constexpr
char
PLT
[]
=
"preload"
;
static
constexpr
size_t
PLTLEN
=
sizeof
(
PLT
)
-
1
;
if
(
first
+
PLPLEN
<
last
&&
*
(
first
+
PLPLEN
-
1
)
==
'"'
&&
std
::
equal
(
PLP
,
PLP
+
PLPLEN
,
first
,
util
::
CaseCmp
()))
{
// we have to search preload in whitespace separated list:
// rel="preload something http://example.org/foo"
first
+=
PLPLEN
;
auto
start
=
first
;
for
(;
first
!=
last
;)
{
if
(
*
first
!=
' '
&&
*
first
!=
'"'
)
{
if
(
!
ign
)
{
// rel can take several relations using quoted form.
static
constexpr
char
PLP
[]
=
"rel=
\"
"
;
static
constexpr
size_t
PLPLEN
=
sizeof
(
PLP
)
-
1
;
static
constexpr
char
PLT
[]
=
"preload"
;
static
constexpr
size_t
PLTLEN
=
sizeof
(
PLT
)
-
1
;
if
(
first
+
PLPLEN
<
last
&&
*
(
first
+
PLPLEN
-
1
)
==
'"'
&&
std
::
equal
(
PLP
,
PLP
+
PLPLEN
,
first
,
util
::
CaseCmp
()))
{
// we have to search preload in whitespace separated list:
// rel="preload something http://example.org/foo"
first
+=
PLPLEN
;
auto
start
=
first
;
for
(;
first
!=
last
;)
{
if
(
*
first
!=
' '
&&
*
first
!=
'"'
)
{
++
first
;
continue
;
}
if
(
start
==
first
)
{
return
{{{
nullptr
,
nullptr
}},
last
};
}
if
(
!
ok
&&
start
+
PLTLEN
==
first
&&
std
::
equal
(
PLT
,
PLT
+
PLTLEN
,
start
,
util
::
CaseCmp
()))
{
ok
=
true
;
}
if
(
*
first
==
'"'
)
{
break
;
}
first
=
skip_lws
(
first
,
last
);
start
=
first
;
}
if
(
first
==
last
)
{
return
{{{
nullptr
,
nullptr
}},
first
};
}
assert
(
*
first
==
'"'
);
++
first
;
if
(
first
==
last
||
*
first
==
','
)
{
goto
almost_done
;
}
if
(
*
first
==
';'
)
{
++
first
;
// parse next link-param
continue
;
}
if
(
start
==
first
)
{
return
{{{
nullptr
,
nullptr
}},
last
};
return
{{{
nullptr
,
nullptr
}},
last
};
}
// we are only interested in rel=preload parameter. Others are
// simply skipped.
static
constexpr
char
PL
[]
=
"rel=preload"
;
static
constexpr
size_t
PLLEN
=
sizeof
(
PL
)
-
1
;
if
(
first
+
PLLEN
==
last
)
{
if
(
std
::
equal
(
PL
,
PL
+
PLLEN
,
first
,
util
::
CaseCmp
()))
{
// ok = true;
// this is the end of sequence
return
{{{
url_first
,
url_last
}},
last
};
}
if
(
!
ok
&&
start
+
PLTLEN
==
first
&&
std
::
equal
(
PLT
,
PLT
+
PLTLEN
,
start
,
util
::
CaseCmp
()))
{
}
else
if
(
first
+
PLLEN
+
1
<=
last
)
{
switch
(
*
(
first
+
PLLEN
))
{
case
','
:
if
(
!
std
::
equal
(
PL
,
PL
+
PLLEN
,
first
,
util
::
CaseCmp
()))
{
break
;
}
// ok = true;
// skip including ','
first
+=
PLLEN
+
1
;
return
{{{
url_first
,
url_last
}},
first
};
case
';'
:
if
(
!
std
::
equal
(
PL
,
PL
+
PLLEN
,
first
,
util
::
CaseCmp
()))
{
break
;
}
ok
=
true
;
// skip including ';'
first
+=
PLLEN
+
1
;
// continue parse next link-param
continue
;
}
if
(
*
first
==
'"'
)
{
break
;
}
first
=
skip_lws
(
first
,
last
);
start
=
first
;
}
if
(
first
==
last
)
{
return
{{{
nullptr
,
nullptr
}},
first
};
}
assert
(
*
first
==
'"'
);
++
first
;
if
(
first
==
last
||
*
first
==
','
)
{
goto
almost_done
;
}
if
(
*
first
==
';'
)
{
++
first
;
// parse next link-param
continue
;
// we have to reject URI if we have nonempty anchor parameter.
static
constexpr
char
ANCHOR
[]
=
"anchor="
;
static
constexpr
size_t
ANCHORLEN
=
sizeof
(
ANCHOR
)
-
1
;
if
(
!
ign
&&
!
check_link_param_empty
(
first
,
last
,
ANCHOR
,
ANCHORLEN
))
{
ign
=
true
;
}
return
{{{
nullptr
,
nullptr
}},
last
};
}
// we are only interested in rel=preload parameter. Others are
// simply skipped.
static
constexpr
char
PL
[]
=
"rel=preload"
;
static
constexpr
size_t
PLLEN
=
sizeof
(
PL
)
-
1
;
if
(
first
+
PLLEN
==
last
)
{
if
(
std
::
equal
(
PL
,
PL
+
PLLEN
,
first
,
util
::
CaseCmp
()))
{
// ok = true;
// this is the end of sequence
return
{{{
url_first
,
url_last
}},
last
};
}
}
else
if
(
first
+
PLLEN
+
1
<=
last
)
{
switch
(
*
(
first
+
PLLEN
))
{
case
','
:
if
(
!
std
::
equal
(
PL
,
PL
+
PLLEN
,
first
,
util
::
CaseCmp
()))
{
break
;
}
// ok = true;
// skip including ','
first
+=
PLLEN
+
1
;
return
{{{
url_first
,
url_last
}},
first
};
case
';'
:
if
(
!
std
::
equal
(
PL
,
PL
+
PLLEN
,
first
,
util
::
CaseCmp
()))
{
break
;
}
ok
=
true
;
// skip including ';'
first
+=
PLLEN
+
1
;
// continue parse next link-param
continue
;
// reject URI if we have non-empty loadpolicy. This could be
// tightened up to just pick up "next" or "insert".
static
constexpr
char
LOADPOLICY
[]
=
"loadpolicy="
;
static
constexpr
size_t
LOADPOLICYLEN
=
sizeof
(
LOADPOLICY
)
-
1
;
if
(
!
ign
&&
!
check_link_param_empty
(
first
,
last
,
LOADPOLICY
,
LOADPOLICYLEN
))
{
ign
=
true
;
}
}
// we have to reject URI if we have nonempty anchor parameter.
static
constexpr
char
ANCHOR
[]
=
"anchor="
;
static
constexpr
size_t
ANCHORLEN
=
sizeof
(
ANCHOR
)
-
1
;
if
(
!
ign
&&
!
check_link_param_empty
(
first
,
last
,
ANCHOR
,
ANCHORLEN
))
{
ign
=
true
;
}
// reject URI if we have non-empty loadpolicy. This could be
// tightened up to just pick up "next" or "insert".
static
constexpr
char
LOADPOLICY
[]
=
"loadpolicy="
;
static
constexpr
size_t
LOADPOLICYLEN
=
sizeof
(
LOADPOLICY
)
-
1
;
if
(
!
ign
&&
!
check_link_param_empty
(
first
,
last
,
LOADPOLICY
,
LOADPOLICYLEN
))
{
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
;
...
...
src/http2_test.cc
View file @
9afc0175
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment