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
acbf38fd
Commit
acbf38fd
authored
Mar 04, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src: Refactor using StringRef, simplify function parameters
parent
1e8bea15
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
191 additions
and
232 deletions
+191
-232
src/asio_server_serve_mux.cc
src/asio_server_serve_mux.cc
+2
-2
src/http2.cc
src/http2.cc
+29
-38
src/http2.h
src/http2.h
+12
-16
src/http2_test.cc
src/http2_test.cc
+144
-171
src/shrpx_http2_upstream.cc
src/shrpx_http2_upstream.cc
+4
-5
No files found.
src/asio_server_serve_mux.cc
View file @
acbf38fd
...
@@ -77,8 +77,8 @@ bool serve_mux::handle(std::string pattern, request_cb cb) {
...
@@ -77,8 +77,8 @@ bool serve_mux::handle(std::string pattern, request_cb cb) {
request_cb
serve_mux
::
handler
(
request_impl
&
req
)
const
{
request_cb
serve_mux
::
handler
(
request_impl
&
req
)
const
{
auto
&
path
=
req
.
uri
().
path
;
auto
&
path
=
req
.
uri
().
path
;
if
(
req
.
method
()
!=
"CONNECT"
)
{
if
(
req
.
method
()
!=
"CONNECT"
)
{
auto
clean_path
=
::
nghttp2
::
http2
::
path_join
(
auto
clean_path
=
::
nghttp2
::
http2
::
path_join
(
StringRef
{},
StringRef
{},
nullptr
,
0
,
nullptr
,
0
,
path
.
c_str
(),
path
.
size
(),
nullptr
,
0
);
StringRef
{
path
},
StringRef
{}
);
if
(
clean_path
!=
path
)
{
if
(
clean_path
!=
path
)
{
auto
new_uri
=
util
::
percent_encode_path
(
clean_path
);
auto
new_uri
=
util
::
percent_encode_path
(
clean_path
);
auto
&
uref
=
req
.
uri
();
auto
&
uref
=
req
.
uri
();
...
...
src/http2.cc
View file @
acbf38fd
...
@@ -1185,39 +1185,37 @@ void eat_dir(std::string &path) {
...
@@ -1185,39 +1185,37 @@ void eat_dir(std::string &path) {
}
}
}
// namespace
}
// namespace
std
::
string
path_join
(
const
char
*
base_path
,
size_t
base_pathlen
,
std
::
string
path_join
(
const
StringRef
&
base_path
,
const
StringRef
&
base_query
,
const
char
*
base_query
,
size_t
base_querylen
,
const
StringRef
&
rel_path
,
const
StringRef
&
rel_query
)
{
const
char
*
rel_path
,
size_t
rel_pathlen
,
const
char
*
rel_query
,
size_t
rel_querylen
)
{
std
::
string
res
;
std
::
string
res
;
if
(
rel_path
len
==
0
)
{
if
(
rel_path
.
empty
()
)
{
if
(
base_path
len
==
0
)
{
if
(
base_path
.
empty
()
)
{
res
=
"/"
;
res
=
"/"
;
}
else
{
}
else
{
res
.
assign
(
base_path
,
base_pathlen
);
res
.
assign
(
std
::
begin
(
base_path
),
std
::
end
(
base_path
)
);
}
}
if
(
rel_query
len
==
0
)
{
if
(
rel_query
.
empty
()
)
{
if
(
base_querylen
)
{
if
(
!
base_query
.
empty
()
)
{
res
+=
'?'
;
res
+=
'?'
;
res
.
append
(
base_query
,
base_querylen
);
res
.
append
(
std
::
begin
(
base_query
),
std
::
end
(
base_query
)
);
}
}
return
res
;
return
res
;
}
}
res
+=
'?'
;
res
+=
'?'
;
res
.
append
(
rel_query
,
rel_querylen
);
res
.
append
(
std
::
begin
(
rel_query
),
std
::
end
(
rel_query
)
);
return
res
;
return
res
;
}
}
auto
first
=
rel_path
;
auto
first
=
std
::
begin
(
rel_path
)
;
auto
last
=
rel_path
+
rel_pathlen
;
auto
last
=
std
::
end
(
rel_path
)
;
if
(
rel_path
[
0
]
==
'/'
)
{
if
(
rel_path
[
0
]
==
'/'
)
{
res
=
"/"
;
res
=
"/"
;
++
first
;
++
first
;
}
else
if
(
base_path
len
==
0
)
{
}
else
if
(
base_path
.
empty
()
)
{
res
=
"/"
;
res
=
"/"
;
}
else
{
}
else
{
res
.
assign
(
base_path
,
base_pathlen
);
res
.
assign
(
std
::
begin
(
base_path
),
std
::
end
(
base_path
)
);
}
}
for
(;
first
!=
last
;)
{
for
(;
first
!=
last
;)
{
...
@@ -1254,9 +1252,9 @@ std::string path_join(const char *base_path, size_t base_pathlen,
...
@@ -1254,9 +1252,9 @@ std::string path_join(const char *base_path, size_t base_pathlen,
for
(;
first
!=
last
&&
*
first
==
'/'
;
++
first
)
for
(;
first
!=
last
&&
*
first
==
'/'
;
++
first
)
;
;
}
}
if
(
rel_querylen
)
{
if
(
!
rel_query
.
empty
()
)
{
res
+=
'?'
;
res
+=
'?'
;
res
.
append
(
rel_query
,
rel_querylen
);
res
.
append
(
std
::
begin
(
rel_query
),
std
::
end
(
rel_query
)
);
}
}
return
res
;
return
res
;
}
}
...
@@ -1480,15 +1478,14 @@ int get_pure_path_component(const char **base, size_t *baselen,
...
@@ -1480,15 +1478,14 @@ int get_pure_path_component(const char **base, size_t *baselen,
}
}
int
construct_push_component
(
std
::
string
&
scheme
,
std
::
string
&
authority
,
int
construct_push_component
(
std
::
string
&
scheme
,
std
::
string
&
authority
,
std
::
string
&
path
,
const
char
*
base
,
std
::
string
&
path
,
const
StringRef
&
base
,
size_t
baselen
,
const
char
*
uri
,
size_t
len
)
{
const
StringRef
&
uri
)
{
int
rv
;
int
rv
;
const
char
*
rel
,
*
relq
=
nullptr
;
StringRef
rel
,
relq
;
size_t
rellen
,
relqlen
=
0
;
http_parser_url
u
{};
http_parser_url
u
{};
rv
=
http_parser_parse_url
(
uri
,
len
,
0
,
&
u
);
rv
=
http_parser_parse_url
(
uri
.
c_str
(),
uri
.
size
()
,
0
,
&
u
);
if
(
rv
!=
0
)
{
if
(
rv
!=
0
)
{
if
(
uri
[
0
]
==
'/'
)
{
if
(
uri
[
0
]
==
'/'
)
{
...
@@ -1496,22 +1493,20 @@ int construct_push_component(std::string &scheme, std::string &authority,
...
@@ -1496,22 +1493,20 @@ int construct_push_component(std::string &scheme, std::string &authority,
}
}
// treat link_url as relative URI.
// treat link_url as relative URI.
auto
end
=
std
::
find
(
uri
,
uri
+
len
,
'#'
);
auto
end
=
std
::
find
(
std
::
begin
(
uri
),
std
::
end
(
uri
)
,
'#'
);
auto
q
=
std
::
find
(
uri
,
end
,
'?'
);
auto
q
=
std
::
find
(
std
::
begin
(
uri
)
,
end
,
'?'
);
rel
=
uri
;
rel
=
StringRef
{
std
::
begin
(
uri
),
q
};
rellen
=
q
-
uri
;
if
(
q
!=
end
)
{
if
(
q
!=
end
)
{
relq
=
q
+
1
;
relq
=
StringRef
{
q
+
1
,
std
::
end
(
uri
)};
relqlen
=
end
-
relq
;
}
}
}
else
{
}
else
{
if
(
u
.
field_set
&
(
1
<<
UF_SCHEMA
))
{
if
(
u
.
field_set
&
(
1
<<
UF_SCHEMA
))
{
http2
::
copy_url_component
(
scheme
,
&
u
,
UF_SCHEMA
,
uri
);
http2
::
copy_url_component
(
scheme
,
&
u
,
UF_SCHEMA
,
uri
.
c_str
()
);
}
}
if
(
u
.
field_set
&
(
1
<<
UF_HOST
))
{
if
(
u
.
field_set
&
(
1
<<
UF_HOST
))
{
http2
::
copy_url_component
(
authority
,
&
u
,
UF_HOST
,
uri
);
http2
::
copy_url_component
(
authority
,
&
u
,
UF_HOST
,
uri
.
c_str
()
);
if
(
u
.
field_set
&
(
1
<<
UF_PORT
))
{
if
(
u
.
field_set
&
(
1
<<
UF_PORT
))
{
authority
+=
':'
;
authority
+=
':'
;
authority
+=
util
::
utos
(
u
.
port
);
authority
+=
util
::
utos
(
u
.
port
);
...
@@ -1520,22 +1515,18 @@ int construct_push_component(std::string &scheme, std::string &authority,
...
@@ -1520,22 +1515,18 @@ int construct_push_component(std::string &scheme, std::string &authority,
if
(
u
.
field_set
&
(
1
<<
UF_PATH
))
{
if
(
u
.
field_set
&
(
1
<<
UF_PATH
))
{
auto
&
f
=
u
.
field_data
[
UF_PATH
];
auto
&
f
=
u
.
field_data
[
UF_PATH
];
rel
=
uri
+
f
.
off
;
rel
=
StringRef
{
uri
.
c_str
()
+
f
.
off
,
f
.
len
};
rellen
=
f
.
len
;
}
else
{
}
else
{
rel
=
"/"
;
rel
=
StringRef
::
from_lit
(
"/"
);
rellen
=
1
;
}
}
if
(
u
.
field_set
&
(
1
<<
UF_QUERY
))
{
if
(
u
.
field_set
&
(
1
<<
UF_QUERY
))
{
auto
&
f
=
u
.
field_data
[
UF_QUERY
];
auto
&
f
=
u
.
field_data
[
UF_QUERY
];
relq
=
uri
+
f
.
off
;
relq
=
StringRef
{
uri
.
c_str
()
+
f
.
off
,
f
.
len
};
relqlen
=
f
.
len
;
}
}
}
}
path
=
path
=
http2
::
path_join
(
base
,
StringRef
{},
rel
,
relq
);
http2
::
path_join
(
base
,
baselen
,
nullptr
,
0
,
rel
,
rellen
,
relq
,
relqlen
);
return
0
;
return
0
;
}
}
...
...
src/http2.h
View file @
acbf38fd
...
@@ -297,16 +297,13 @@ struct LinkHeader {
...
@@ -297,16 +297,13 @@ struct LinkHeader {
// is ignored during parsing.
// is ignored during parsing.
std
::
vector
<
LinkHeader
>
parse_link_header
(
const
char
*
src
,
size_t
len
);
std
::
vector
<
LinkHeader
>
parse_link_header
(
const
char
*
src
,
size_t
len
);
// Constructs path by combining base path |base_path| of length
// Constructs path by combining base path |base_path| with another
// |base_pathlen| with another path |rel_path| of length
// path |rel_path|. The base path and another path can have optional
// |rel_pathlen|. The base path and another path can have optional
// query component. This function assumes |base_path| is normalized.
// query component. This function assumes |base_path| is normalized.
// In other words, it does not contain ".." or "." path components
// In other words, it does not contain ".." or "." path components
// and starts with "/" if it is not empty.
// and starts with "/" if it is not empty.
std
::
string
path_join
(
const
char
*
base_path
,
size_t
base_pathlen
,
std
::
string
path_join
(
const
StringRef
&
base
,
const
StringRef
&
base_query
,
const
char
*
base_query
,
size_t
base_querylen
,
const
StringRef
&
rel_path
,
const
StringRef
&
rel_query
);
const
char
*
rel_path
,
size_t
rel_pathlen
,
const
char
*
rel_query
,
size_t
rel_querylen
);
// true if response has body, taking into account the request method
// true if response has body, taking into account the request method
// and status code.
// and status code.
...
@@ -359,8 +356,7 @@ std::string normalize_path(InputIt first, InputIt last) {
...
@@ -359,8 +356,7 @@ std::string normalize_path(InputIt first, InputIt last) {
}
}
result
.
append
(
first
,
last
);
result
.
append
(
first
,
last
);
}
}
return
path_join
(
nullptr
,
0
,
nullptr
,
0
,
result
.
c_str
(),
result
.
size
(),
return
path_join
(
StringRef
{},
StringRef
{},
StringRef
{
result
},
StringRef
{});
nullptr
,
0
);
}
}
template
<
typename
InputIt
>
template
<
typename
InputIt
>
...
@@ -384,14 +380,14 @@ std::string rewrite_clean_path(InputIt first, InputIt last) {
...
@@ -384,14 +380,14 @@ std::string rewrite_clean_path(InputIt first, InputIt last) {
int
get_pure_path_component
(
const
char
**
base
,
size_t
*
baselen
,
int
get_pure_path_component
(
const
char
**
base
,
size_t
*
baselen
,
const
std
::
string
&
uri
);
const
std
::
string
&
uri
);
// Deduces scheme, authority and path from given |uri|
of length
// Deduces scheme, authority and path from given |uri|
, and stores
//
|len|, and stores them in |scheme|, |authority|, and |path
|
//
them in |scheme|, |authority|, and |path| respectively. If |uri
|
//
respectively. If |uri| is relative path, path resolution is take
n
//
is relative path, path resolution takes place using path given i
n
//
palce using path given in |base| of length |baselen|. This
//
|base| of length |baselen|. This function returns 0 if it
//
function returns 0 if it
succeeds, or -1.
// succeeds, or -1.
int
construct_push_component
(
std
::
string
&
scheme
,
std
::
string
&
authority
,
int
construct_push_component
(
std
::
string
&
scheme
,
std
::
string
&
authority
,
std
::
string
&
path
,
const
char
*
base
,
std
::
string
&
path
,
const
StringRef
&
base
,
size_t
baselen
,
const
char
*
uri
,
size_t
len
);
const
StringRef
&
uri
);
}
// namespace http2
}
// namespace http2
...
...
src/http2_test.cc
View file @
acbf38fd
...
@@ -283,21 +283,21 @@ void test_http2_parse_link_header(void) {
...
@@ -283,21 +283,21 @@ void test_http2_parse_link_header(void) {
constexpr
char
s
[]
=
"<url>; rel=preload"
;
constexpr
char
s
[]
=
"<url>; rel=preload"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// With extra link-param. URI url should be extracted
// With extra link-param. URI url should be extracted
constexpr
char
s
[]
=
"<url>; rel=preload; as=file"
;
constexpr
char
s
[]
=
"<url>; rel=preload; as=file"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// With extra link-param. URI url should be extracted
// With extra link-param. URI url should be extracted
constexpr
char
s
[]
=
"<url>; as=file; rel=preload"
;
constexpr
char
s
[]
=
"<url>; as=file; rel=preload"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// With extra link-param and quote-string. URI url should be
// With extra link-param and quote-string. URI url should be
...
@@ -305,7 +305,7 @@ void test_http2_parse_link_header(void) {
...
@@ -305,7 +305,7 @@ void test_http2_parse_link_header(void) {
constexpr
char
s
[]
=
R"(<url>; rel=preload; title="foo,bar")"
;
constexpr
char
s
[]
=
R"(<url>; rel=preload; title="foo,bar")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// With extra link-param and quote-string. URI url should be
// With extra link-param and quote-string. URI url should be
...
@@ -313,36 +313,37 @@ void test_http2_parse_link_header(void) {
...
@@ -313,36 +313,37 @@ void test_http2_parse_link_header(void) {
constexpr
char
s
[]
=
R"(<url>; title="foo,bar"; rel=preload)"
;
constexpr
char
s
[]
=
R"(<url>; title="foo,bar"; rel=preload)"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// ',' after quote-string
// ',' after quote-string
constexpr
char
s
[]
=
R"(<url>; title="foo,bar", <url>; rel=preload)"
;
constexpr
char
s
[]
=
R"(<url>; title="foo,bar", <url
2
>; rel=preload)"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
25
],
&
s
[
28
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url2"
==
res
[
0
].
uri
);
CU_ASSERT
(
&
s
[
25
]
==
&
res
[
0
].
uri
[
0
]);
}
}
{
{
// Only first URI should be extracted.
// Only first URI should be extracted.
constexpr
char
s
[]
=
"<url>; rel=preload, <url>"
;
constexpr
char
s
[]
=
"<url>; rel=preload, <url
2
>"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// Both have rel=preload, so both urls should be extracted
// Both have rel=preload, so both urls should be extracted
constexpr
char
s
[]
=
"<url>; rel=preload, <url>; rel=preload"
;
constexpr
char
s
[]
=
"<url>; rel=preload, <url
2
>; rel=preload"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
2
==
res
.
size
());
CU_ASSERT
(
2
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
CU_ASSERT
(
std
::
make_pair
(
&
s
[
21
],
&
s
[
24
])
==
res
[
1
].
uri
);
CU_ASSERT
(
"url2"
==
res
[
1
].
uri
);
}
}
{
{
// Second URI uri should be extracted.
// Second URI uri should be extracted.
constexpr
char
s
[]
=
"<url>, <url>;rel=preload"
;
constexpr
char
s
[]
=
"<url>, <url
2
>;rel=preload"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
8
],
&
s
[
11
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url2"
==
res
[
0
].
uri
);
}
}
{
{
// Error if input ends with ';'
// Error if input ends with ';'
...
@@ -361,14 +362,14 @@ void test_http2_parse_link_header(void) {
...
@@ -361,14 +362,14 @@ void test_http2_parse_link_header(void) {
constexpr
char
s
[]
=
"<url>;rel=preload,"
;
constexpr
char
s
[]
=
"<url>;rel=preload,"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// Multiple repeated ','s between fields is OK
// Multiple repeated ','s between fields is OK
constexpr
char
s
[]
=
"<url>,,,<url>;rel=preload"
;
constexpr
char
s
[]
=
"<url>,,,<url
2
>;rel=preload"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
9
],
&
s
[
12
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url2"
==
res
[
0
].
uri
);
}
}
{
{
// Error if url is not enclosed by <>
// Error if url is not enclosed by <>
...
@@ -408,25 +409,25 @@ void test_http2_parse_link_header(void) {
...
@@ -408,25 +409,25 @@ void test_http2_parse_link_header(void) {
}
}
{
{
// Without whitespaces
// Without whitespaces
constexpr
char
s
[]
=
"<url>;as=file;rel=preload,<url>;rel=preload"
;
constexpr
char
s
[]
=
"<url>;as=file;rel=preload,<url
2
>;rel=preload"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
2
==
res
.
size
());
CU_ASSERT
(
2
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
CU_ASSERT
(
std
::
make_pair
(
&
s
[
27
],
&
s
[
30
])
==
res
[
1
].
uri
);
CU_ASSERT
(
"url2"
==
res
[
1
].
uri
);
}
}
{
{
// link-extension may have no value
// link-extension may have no value
constexpr
char
s
[]
=
"<url>; as; rel=preload"
;
constexpr
char
s
[]
=
"<url>; as; rel=preload"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// ext-name-star
// ext-name-star
constexpr
char
s
[]
=
"<url>; foo*=bar; rel=preload"
;
constexpr
char
s
[]
=
"<url>; foo*=bar; rel=preload"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// '*' is not allowed expect for trailing one
// '*' is not allowed expect for trailing one
...
@@ -457,7 +458,7 @@ void test_http2_parse_link_header(void) {
...
@@ -457,7 +458,7 @@ void test_http2_parse_link_header(void) {
constexpr
char
s
[]
=
" <url>; rel=preload"
;
constexpr
char
s
[]
=
" <url>; rel=preload"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
3
],
&
s
[
6
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// preload is a prefix of bogus rel parameter value
// preload is a prefix of bogus rel parameter value
...
@@ -470,35 +471,35 @@ void test_http2_parse_link_header(void) {
...
@@ -470,35 +471,35 @@ void test_http2_parse_link_header(void) {
constexpr
char
s
[]
=
R"(<url>; rel="preload")"
;
constexpr
char
s
[]
=
R"(<url>; rel="preload")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// preload in relation-types list followed by another parameter
// preload in relation-types list followed by another parameter
constexpr
char
s
[]
=
R"(<url>; rel="preload foo")"
;
constexpr
char
s
[]
=
R"(<url>; rel="preload foo")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// preload in relation-types list following another parameter
// preload in relation-types list following another parameter
constexpr
char
s
[]
=
R"(<url>; rel="foo preload")"
;
constexpr
char
s
[]
=
R"(<url>; rel="foo preload")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// preload in relation-types list between other parameters
// preload in relation-types list between other parameters
constexpr
char
s
[]
=
R"(<url>; rel="foo preload bar")"
;
constexpr
char
s
[]
=
R"(<url>; rel="foo preload bar")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// preload in relation-types list between other parameters
// preload in relation-types list between other parameters
constexpr
char
s
[]
=
R"(<url>; rel="foo preload bar")"
;
constexpr
char
s
[]
=
R"(<url>; rel="foo preload bar")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// no preload in relation-types list
// no preload in relation-types list
...
@@ -514,24 +515,24 @@ void test_http2_parse_link_header(void) {
...
@@ -514,24 +515,24 @@ void test_http2_parse_link_header(void) {
}
}
{
{
// preload in relation-types list, followed by another link-value.
// preload in relation-types list, followed by another link-value.
constexpr
char
s
[]
=
R"(<url>; rel="preload", <url>)"
;
constexpr
char
s
[]
=
R"(<url>; rel="preload", <url
2
>)"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// preload in relation-types list, following another link-value.
// preload in relation-types list, following another link-value.
constexpr
char
s
[]
=
R"(<url>, <url>; rel="preload")"
;
constexpr
char
s
[]
=
R"(<url>, <url
2
>; rel="preload")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
8
],
&
s
[
11
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url2"
==
res
[
0
].
uri
);
}
}
{
{
// preload in relation-types list, followed by another link-param.
// preload in relation-types list, followed by another link-param.
constexpr
char
s
[]
=
R"(<url>; rel="preload"; as="font")"
;
constexpr
char
s
[]
=
R"(<url>; rel="preload"; as="font")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// preload in relation-types list, followed by character other
// preload in relation-types list, followed by character other
...
@@ -553,7 +554,7 @@ void test_http2_parse_link_header(void) {
...
@@ -553,7 +554,7 @@ void test_http2_parse_link_header(void) {
constexpr
char
s
[]
=
R"(<url>; rel="preload",)"
;
constexpr
char
s
[]
=
R"(<url>; rel="preload",)"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// preload in relation-types list but there is preceding white
// preload in relation-types list but there is preceding white
...
@@ -574,14 +575,14 @@ void test_http2_parse_link_header(void) {
...
@@ -574,14 +575,14 @@ void test_http2_parse_link_header(void) {
constexpr
char
s
[]
=
R"(<url>; rel=preload; title="foo\"baz\"bar")"
;
constexpr
char
s
[]
=
R"(<url>; rel=preload; title="foo\"baz\"bar")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// anchor="" is acceptable
// anchor="" is acceptable
constexpr
char
s
[]
=
R"(<url>; rel=preload; anchor="")"
;
constexpr
char
s
[]
=
R"(<url>; rel=preload; anchor="")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// With anchor="#foo", url should be ignored
// With anchor="#foo", url should be ignored
...
@@ -599,10 +600,10 @@ void test_http2_parse_link_header(void) {
...
@@ -599,10 +600,10 @@ void test_http2_parse_link_header(void) {
// First url is ignored With anchor="#foo", but url should be
// First url is ignored With anchor="#foo", but url should be
// accepted.
// accepted.
constexpr
char
s
[]
=
constexpr
char
s
[]
=
R"(<url>; rel=preload; anchor="#foo", <url>; rel=preload)"
;
R"(<url>; rel=preload; anchor="#foo", <url
2
>; rel=preload)"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
36
],
&
s
[
39
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url2"
==
res
[
0
].
uri
);
}
}
{
{
// With loadpolicy="next", url should be ignored
// With loadpolicy="next", url should be ignored
...
@@ -615,16 +616,16 @@ void test_http2_parse_link_header(void) {
...
@@ -615,16 +616,16 @@ void test_http2_parse_link_header(void) {
constexpr
char
s
[]
=
R"(<url>; rel=preload; loadpolicy="")"
;
constexpr
char
s
[]
=
R"(<url>; rel=preload; loadpolicy="")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// case-insensitive match
// case-insensitive match
constexpr
char
s
[]
=
R"(<url>; rel=preload; ANCHOR="#foo", <url>; )"
constexpr
char
s
[]
=
R"(<url>; rel=preload; ANCHOR="#foo", <url
2
>; )"
R"(REL=PRELOAD, <url>; REL="foo PRELOAD bar")"
;
R"(REL=PRELOAD, <url
3
>; REL="foo PRELOAD bar")"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
2
==
res
.
size
());
CU_ASSERT
(
2
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
36
],
&
s
[
39
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url2"
==
res
[
0
].
uri
);
CU_ASSERT
(
std
::
make_pair
(
&
s
[
42
+
14
],
&
s
[
42
+
17
])
==
res
[
1
].
uri
);
CU_ASSERT
(
"url3"
==
res
[
1
].
uri
);
}
}
{
{
// nopush at the end of input
// nopush at the end of input
...
@@ -649,186 +650,166 @@ void test_http2_parse_link_header(void) {
...
@@ -649,186 +650,166 @@ void test_http2_parse_link_header(void) {
constexpr
char
s
[]
=
"<url>; nopushyes; rel=preload"
;
constexpr
char
s
[]
=
"<url>; nopushyes; rel=preload"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
{
{
// rel=preload twice
// rel=preload twice
constexpr
char
s
[]
=
"<url>; rel=preload; rel=preload"
;
constexpr
char
s
[]
=
"<url>; rel=preload; rel=preload"
;
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
auto
res
=
http2
::
parse_link_header
(
s
,
str_size
(
s
));
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
std
::
make_pair
(
&
s
[
1
],
&
s
[
4
])
==
res
[
0
].
uri
);
CU_ASSERT
(
"url"
==
res
[
0
].
uri
);
}
}
}
}
void
test_http2_path_join
(
void
)
{
void
test_http2_path_join
(
void
)
{
{
{
const
char
base
[]
=
"/"
;
auto
base
=
StringRef
::
from_lit
(
"/"
);
const
char
rel
[]
=
"/"
;
auto
rel
=
StringRef
::
from_lit
(
"/"
);
CU_ASSERT
(
"/"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
rel
,
CU_ASSERT
(
"/"
==
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
{
{
const
char
base
[]
=
"/"
;
auto
base
=
StringRef
::
from_lit
(
"/"
)
;
const
char
rel
[]
=
"/alpha"
;
auto
rel
=
StringRef
::
from_lit
(
"/alpha"
)
;
CU_ASSERT
(
"/alpha"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
CU_ASSERT
(
"/alpha"
==
rel
,
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}
));
}
}
{
{
// rel ends with trailing '/'
// rel ends with trailing '/'
const
char
base
[]
=
"/"
;
auto
base
=
StringRef
::
from_lit
(
"/"
)
;
const
char
rel
[]
=
"/alpha/"
;
auto
rel
=
StringRef
::
from_lit
(
"/alpha/"
)
;
CU_ASSERT
(
"/alpha/"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
CU_ASSERT
(
"/alpha/"
==
rel
,
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}
));
}
}
{
{
// rel contains multiple components
// rel contains multiple components
const
char
base
[]
=
"/"
;
auto
base
=
StringRef
::
from_lit
(
"/"
);
const
char
rel
[]
=
"/alpha/bravo"
;
auto
rel
=
StringRef
::
from_lit
(
"/alpha/bravo"
);
CU_ASSERT
(
"/alpha/bravo"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
CU_ASSERT
(
"/alpha/bravo"
==
nullptr
,
0
,
rel
,
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
{
{
// rel is relative
// rel is relative
const
char
base
[]
=
"/"
;
auto
base
=
StringRef
::
from_lit
(
"/"
);
const
char
rel
[]
=
"alpha/bravo"
;
auto
rel
=
StringRef
::
from_lit
(
"alpha/bravo"
);
CU_ASSERT
(
"/alpha/bravo"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
CU_ASSERT
(
"/alpha/bravo"
==
nullptr
,
0
,
rel
,
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
{
{
// rel is relative and base ends without /, which means it refers
// rel is relative and base ends without /, which means it refers
// to file.
// to file.
const
char
base
[]
=
"/alpha"
;
auto
base
=
StringRef
::
from_lit
(
"/alpha"
)
;
const
char
rel
[]
=
"bravo/charlie"
;
auto
rel
=
StringRef
::
from_lit
(
"bravo/charlie"
)
;
CU_ASSERT
(
"/bravo/charlie"
==
CU_ASSERT
(
"/bravo/charlie"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
rel
,
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
{
{
// rel contains repeated '/'s
// rel contains repeated '/'s
const
char
base
[]
=
"/"
;
auto
base
=
StringRef
::
from_lit
(
"/"
);
const
char
rel
[]
=
"/alpha/////bravo/////"
;
auto
rel
=
StringRef
::
from_lit
(
"/alpha/////bravo/////"
);
CU_ASSERT
(
"/alpha/bravo/"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
CU_ASSERT
(
"/alpha/bravo/"
==
nullptr
,
0
,
rel
,
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
{
{
// base ends with '/', so '..' eats 'bravo'
// base ends with '/', so '..' eats 'bravo'
const
char
base
[]
=
"/alpha/bravo/"
;
auto
base
=
StringRef
::
from_lit
(
"/alpha/bravo/"
)
;
const
char
rel
[]
=
"../charlie/delta"
;
auto
rel
=
StringRef
::
from_lit
(
"../charlie/delta"
)
;
CU_ASSERT
(
"/alpha/charlie/delta"
==
CU_ASSERT
(
"/alpha/charlie/delta"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
rel
,
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
{
{
// base does not end with '/', so '..' eats 'alpha/bravo'
// base does not end with '/', so '..' eats 'alpha/bravo'
const
char
base
[]
=
"/alpha/bravo"
;
auto
base
=
StringRef
::
from_lit
(
"/alpha/bravo"
)
;
const
char
rel
[]
=
"../charlie"
;
auto
rel
=
StringRef
::
from_lit
(
"../charlie"
)
;
CU_ASSERT
(
"/charlie"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
CU_ASSERT
(
"/charlie"
==
rel
,
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}
));
}
}
{
{
// 'charlie' is eaten by following '..'
// 'charlie' is eaten by following '..'
const
char
base
[]
=
"/alpha/bravo/"
;
auto
base
=
StringRef
::
from_lit
(
"/alpha/bravo/"
);
const
char
rel
[]
=
"../charlie/../delta"
;
auto
rel
=
StringRef
::
from_lit
(
"../charlie/../delta"
);
CU_ASSERT
(
"/alpha/delta"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
CU_ASSERT
(
"/alpha/delta"
==
nullptr
,
0
,
rel
,
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
{
{
// excessive '..' results in '/'
// excessive '..' results in '/'
const
char
base
[]
=
"/alpha/bravo/"
;
auto
base
=
StringRef
::
from_lit
(
"/alpha/bravo/"
);
const
char
rel
[]
=
"../../../"
;
auto
rel
=
StringRef
::
from_lit
(
"../../../"
);
CU_ASSERT
(
"/"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
rel
,
CU_ASSERT
(
"/"
==
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
{
{
// excessive '..' and path component
// excessive '..' and path component
const
char
base
[]
=
"/alpha/bravo/"
;
auto
base
=
StringRef
::
from_lit
(
"/alpha/bravo/"
)
;
const
char
rel
[]
=
"../../../charlie"
;
auto
rel
=
StringRef
::
from_lit
(
"../../../charlie"
)
;
CU_ASSERT
(
"/charlie"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
CU_ASSERT
(
"/charlie"
==
rel
,
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}
));
}
}
{
{
// rel ends with '..'
// rel ends with '..'
const
char
base
[]
=
"/alpha/bravo/"
;
auto
base
=
StringRef
::
from_lit
(
"/alpha/bravo/"
);
const
char
rel
[]
=
"charlie/.."
;
auto
rel
=
StringRef
::
from_lit
(
"charlie/.."
);
CU_ASSERT
(
"/alpha/bravo/"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
CU_ASSERT
(
"/alpha/bravo/"
==
nullptr
,
0
,
rel
,
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
{
{
// base empty and rel contains '..'
// base empty and rel contains '..'
const
char
base
[]
=
""
;
auto
base
=
StringRef
{};
const
char
rel
[]
=
"charlie/.."
;
auto
rel
=
StringRef
::
from_lit
(
"charlie/.."
);
CU_ASSERT
(
"/"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
rel
,
CU_ASSERT
(
"/"
==
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
{
{
// '.' is ignored
// '.' is ignored
const
char
base
[]
=
"/"
;
auto
base
=
StringRef
::
from_lit
(
"/"
)
;
const
char
rel
[]
=
"charlie/././././delta"
;
auto
rel
=
StringRef
::
from_lit
(
"charlie/././././delta"
)
;
CU_ASSERT
(
"/charlie/delta"
==
CU_ASSERT
(
"/charlie/delta"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
rel
,
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
{
{
// trailing '.' is ignored
// trailing '.' is ignored
const
char
base
[]
=
"/"
;
auto
base
=
StringRef
::
from_lit
(
"/"
);
const
char
rel
[]
=
"charlie/."
;
auto
rel
=
StringRef
::
from_lit
(
"charlie/."
);
CU_ASSERT
(
"/charlie/"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
CU_ASSERT
(
"/charlie/"
==
0
,
rel
,
sizeof
(
rel
)
-
1
,
nullptr
,
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}));
0
));
}
}
{
{
// query
// query
const
char
base
[]
=
"/"
;
auto
base
=
StringRef
::
from_lit
(
"/"
);
const
char
rel
[]
=
"/"
;
auto
rel
=
StringRef
::
from_lit
(
"/"
);
const
char
relq
[]
=
"q"
;
auto
relq
=
StringRef
::
from_lit
(
"q"
);
CU_ASSERT
(
"/?q"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
rel
,
CU_ASSERT
(
"/?q"
==
http2
::
path_join
(
base
,
StringRef
{},
rel
,
relq
));
sizeof
(
rel
)
-
1
,
relq
,
sizeof
(
relq
)
-
1
));
}
}
{
{
// empty rel and query
// empty rel and query
const
char
base
[]
=
"/alpha"
;
auto
base
=
StringRef
::
from_lit
(
"/alpha"
);
const
char
rel
[]
=
""
;
auto
rel
=
StringRef
{};
const
char
relq
[]
=
"q"
;
auto
relq
=
StringRef
::
from_lit
(
"q"
);
CU_ASSERT
(
"/alpha?q"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
CU_ASSERT
(
"/alpha?q"
==
http2
::
path_join
(
base
,
StringRef
{},
rel
,
relq
));
rel
,
sizeof
(
rel
)
-
1
,
relq
,
sizeof
(
relq
)
-
1
));
}
}
{
{
// both rel and query are empty
// both rel and query are empty
const
char
base
[]
=
"/alpha"
;
auto
base
=
StringRef
::
from_lit
(
"/alpha"
);
const
char
baseq
[]
=
"r"
;
auto
baseq
=
StringRef
::
from_lit
(
"r"
);
const
char
rel
[]
=
""
;
auto
rel
=
StringRef
{};
const
char
relq
[]
=
""
;
auto
relq
=
StringRef
{};
CU_ASSERT
(
"/alpha?r"
==
CU_ASSERT
(
"/alpha?r"
==
http2
::
path_join
(
base
,
baseq
,
rel
,
relq
));
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
baseq
,
sizeof
(
baseq
)
-
1
,
rel
,
sizeof
(
rel
)
-
1
,
relq
,
sizeof
(
relq
)
-
1
));
}
}
{
{
// empty base
// empty base
const
char
base
[]
=
""
;
auto
base
=
StringRef
{}
;
const
char
rel
[]
=
"/alpha"
;
auto
rel
=
StringRef
::
from_lit
(
"/alpha"
)
;
CU_ASSERT
(
"/alpha"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
nullptr
,
0
,
CU_ASSERT
(
"/alpha"
==
rel
,
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
http2
::
path_join
(
base
,
StringRef
{},
rel
,
StringRef
{}
));
}
}
{
{
// everything is empty
// everything is empty
CU_ASSERT
(
"/"
==
CU_ASSERT
(
"/"
==
http2
::
path_join
(
StringRef
{},
StringRef
{},
StringRef
{},
http2
::
path_join
(
nullptr
,
0
,
nullptr
,
0
,
nullptr
,
0
,
nullptr
,
0
));
StringRef
{}
));
}
}
{
{
// only baseq is not empty
// only baseq is not empty
const
char
base
[]
=
""
;
auto
base
=
StringRef
{};
const
char
baseq
[]
=
"r"
;
auto
baseq
=
StringRef
::
from_lit
(
"r"
);
const
char
rel
[]
=
""
;
auto
rel
=
StringRef
{};
CU_ASSERT
(
"/?r"
==
http2
::
path_join
(
base
,
sizeof
(
base
)
-
1
,
baseq
,
CU_ASSERT
(
"/?r"
==
http2
::
path_join
(
base
,
baseq
,
rel
,
StringRef
{}));
sizeof
(
baseq
)
-
1
,
rel
,
sizeof
(
rel
)
-
1
,
nullptr
,
0
));
}
}
}
}
...
@@ -914,19 +895,15 @@ void test_http2_get_pure_path_component(void) {
...
@@ -914,19 +895,15 @@ void test_http2_get_pure_path_component(void) {
}
}
void
test_http2_construct_push_component
(
void
)
{
void
test_http2_construct_push_component
(
void
)
{
const
char
*
base
;
StringRef
base
,
uri
;
size_t
baselen
;
std
::
string
uri
;
std
::
string
scheme
,
authority
,
path
;
std
::
string
scheme
,
authority
,
path
;
base
=
"/b/"
;
base
=
StringRef
::
from_lit
(
"/b/"
);
baselen
=
3
;
uri
=
"https://example.org/foo"
;
uri
=
StringRef
::
from_lit
(
"https://example.org/foo"
)
;
CU_ASSERT
(
0
==
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
CU_ASSERT
(
baselen
,
uri
.
c_str
(),
0
==
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
uri
));
uri
.
size
()));
CU_ASSERT
(
"https"
==
scheme
);
CU_ASSERT
(
"https"
==
scheme
);
CU_ASSERT
(
"example.org"
==
authority
);
CU_ASSERT
(
"example.org"
==
authority
);
CU_ASSERT
(
"/foo"
==
path
);
CU_ASSERT
(
"/foo"
==
path
);
...
@@ -935,11 +912,10 @@ void test_http2_construct_push_component(void) {
...
@@ -935,11 +912,10 @@ void test_http2_construct_push_component(void) {
authority
.
clear
();
authority
.
clear
();
path
.
clear
();
path
.
clear
();
uri
=
"/foo/bar?q=a"
;
uri
=
StringRef
::
from_lit
(
"/foo/bar?q=a"
)
;
CU_ASSERT
(
0
==
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
CU_ASSERT
(
baselen
,
uri
.
c_str
(),
0
==
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
uri
));
uri
.
size
()));
CU_ASSERT
(
""
==
scheme
);
CU_ASSERT
(
""
==
scheme
);
CU_ASSERT
(
""
==
authority
);
CU_ASSERT
(
""
==
authority
);
CU_ASSERT
(
"/foo/bar?q=a"
==
path
);
CU_ASSERT
(
"/foo/bar?q=a"
==
path
);
...
@@ -948,11 +924,10 @@ void test_http2_construct_push_component(void) {
...
@@ -948,11 +924,10 @@ void test_http2_construct_push_component(void) {
authority
.
clear
();
authority
.
clear
();
path
.
clear
();
path
.
clear
();
uri
=
"foo/../bar?q=a"
;
uri
=
StringRef
::
from_lit
(
"foo/../bar?q=a"
)
;
CU_ASSERT
(
0
==
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
CU_ASSERT
(
baselen
,
uri
.
c_str
(),
0
==
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
uri
));
uri
.
size
()));
CU_ASSERT
(
""
==
scheme
);
CU_ASSERT
(
""
==
scheme
);
CU_ASSERT
(
""
==
authority
);
CU_ASSERT
(
""
==
authority
);
CU_ASSERT
(
"/b/bar?q=a"
==
path
);
CU_ASSERT
(
"/b/bar?q=a"
==
path
);
...
@@ -961,11 +936,10 @@ void test_http2_construct_push_component(void) {
...
@@ -961,11 +936,10 @@ void test_http2_construct_push_component(void) {
authority
.
clear
();
authority
.
clear
();
path
.
clear
();
path
.
clear
();
uri
=
""
;
uri
=
StringRef
{}
;
CU_ASSERT
(
0
==
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
CU_ASSERT
(
baselen
,
uri
.
c_str
(),
0
==
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
uri
));
uri
.
size
()));
CU_ASSERT
(
""
==
scheme
);
CU_ASSERT
(
""
==
scheme
);
CU_ASSERT
(
""
==
authority
);
CU_ASSERT
(
""
==
authority
);
CU_ASSERT
(
"/"
==
path
);
CU_ASSERT
(
"/"
==
path
);
...
@@ -974,11 +948,10 @@ void test_http2_construct_push_component(void) {
...
@@ -974,11 +948,10 @@ void test_http2_construct_push_component(void) {
authority
.
clear
();
authority
.
clear
();
path
.
clear
();
path
.
clear
();
uri
=
"?q=a"
;
uri
=
StringRef
::
from_lit
(
"?q=a"
)
;
CU_ASSERT
(
0
==
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
CU_ASSERT
(
baselen
,
uri
.
c_str
(),
0
==
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
uri
));
uri
.
size
()));
CU_ASSERT
(
""
==
scheme
);
CU_ASSERT
(
""
==
scheme
);
CU_ASSERT
(
""
==
authority
);
CU_ASSERT
(
""
==
authority
);
CU_ASSERT
(
"/b/?q=a"
==
path
);
CU_ASSERT
(
"/b/?q=a"
==
path
);
...
...
src/shrpx_http2_upstream.cc
View file @
acbf38fd
...
@@ -1755,9 +1755,8 @@ int Http2Upstream::prepare_push_promise(Downstream *downstream) {
...
@@ -1755,9 +1755,8 @@ int Http2Upstream::prepare_push_promise(Downstream *downstream) {
const
std
::
string
*
scheme_ptr
,
*
authority_ptr
;
const
std
::
string
*
scheme_ptr
,
*
authority_ptr
;
std
::
string
scheme
,
authority
,
path
;
std
::
string
scheme
,
authority
,
path
;
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
baselen
,
link
.
uri
.
c_str
(),
StringRef
{
base
,
baselen
},
link
.
uri
);
link
.
uri
.
size
());
if
(
rv
!=
0
)
{
if
(
rv
!=
0
)
{
continue
;
continue
;
}
}
...
@@ -1872,8 +1871,8 @@ int Http2Upstream::initiate_push(Downstream *downstream, const char *uri,
...
@@ -1872,8 +1871,8 @@ int Http2Upstream::initiate_push(Downstream *downstream, const char *uri,
const
std
::
string
*
scheme_ptr
,
*
authority_ptr
;
const
std
::
string
*
scheme_ptr
,
*
authority_ptr
;
std
::
string
scheme
,
authority
,
path
;
std
::
string
scheme
,
authority
,
path
;
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
baselen
,
rv
=
http2
::
construct_push_component
(
uri
,
len
);
scheme
,
authority
,
path
,
StringRef
{
base
,
baselen
},
StringRef
{
uri
,
len
}
);
if
(
rv
!=
0
)
{
if
(
rv
!=
0
)
{
return
-
1
;
return
-
1
;
}
}
...
...
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