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
Expand all
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) {
request_cb
serve_mux
::
handler
(
request_impl
&
req
)
const
{
auto
&
path
=
req
.
uri
().
path
;
if
(
req
.
method
()
!=
"CONNECT"
)
{
auto
clean_path
=
::
nghttp2
::
http2
::
path_join
(
nullptr
,
0
,
nullptr
,
0
,
path
.
c_str
(),
path
.
size
(),
nullptr
,
0
);
auto
clean_path
=
::
nghttp2
::
http2
::
path_join
(
StringRef
{},
StringRef
{},
StringRef
{
path
},
StringRef
{}
);
if
(
clean_path
!=
path
)
{
auto
new_uri
=
util
::
percent_encode_path
(
clean_path
);
auto
&
uref
=
req
.
uri
();
...
...
src/http2.cc
View file @
acbf38fd
...
...
@@ -1185,39 +1185,37 @@ void eat_dir(std::string &path) {
}
}
// namespace
std
::
string
path_join
(
const
char
*
base_path
,
size_t
base_pathlen
,
const
char
*
base_query
,
size_t
base_querylen
,
const
char
*
rel_path
,
size_t
rel_pathlen
,
const
char
*
rel_query
,
size_t
rel_querylen
)
{
std
::
string
path_join
(
const
StringRef
&
base_path
,
const
StringRef
&
base_query
,
const
StringRef
&
rel_path
,
const
StringRef
&
rel_query
)
{
std
::
string
res
;
if
(
rel_path
len
==
0
)
{
if
(
base_path
len
==
0
)
{
if
(
rel_path
.
empty
()
)
{
if
(
base_path
.
empty
()
)
{
res
=
"/"
;
}
else
{
res
.
assign
(
base_path
,
base_pathlen
);
res
.
assign
(
std
::
begin
(
base_path
),
std
::
end
(
base_path
)
);
}
if
(
rel_query
len
==
0
)
{
if
(
base_querylen
)
{
if
(
rel_query
.
empty
()
)
{
if
(
!
base_query
.
empty
()
)
{
res
+=
'?'
;
res
.
append
(
base_query
,
base_querylen
);
res
.
append
(
std
::
begin
(
base_query
),
std
::
end
(
base_query
)
);
}
return
res
;
}
res
+=
'?'
;
res
.
append
(
rel_query
,
rel_querylen
);
res
.
append
(
std
::
begin
(
rel_query
),
std
::
end
(
rel_query
)
);
return
res
;
}
auto
first
=
rel_path
;
auto
last
=
rel_path
+
rel_pathlen
;
auto
first
=
std
::
begin
(
rel_path
)
;
auto
last
=
std
::
end
(
rel_path
)
;
if
(
rel_path
[
0
]
==
'/'
)
{
res
=
"/"
;
++
first
;
}
else
if
(
base_path
len
==
0
)
{
}
else
if
(
base_path
.
empty
()
)
{
res
=
"/"
;
}
else
{
res
.
assign
(
base_path
,
base_pathlen
);
res
.
assign
(
std
::
begin
(
base_path
),
std
::
end
(
base_path
)
);
}
for
(;
first
!=
last
;)
{
...
...
@@ -1254,9 +1252,9 @@ std::string path_join(const char *base_path, size_t base_pathlen,
for
(;
first
!=
last
&&
*
first
==
'/'
;
++
first
)
;
}
if
(
rel_querylen
)
{
if
(
!
rel_query
.
empty
()
)
{
res
+=
'?'
;
res
.
append
(
rel_query
,
rel_querylen
);
res
.
append
(
std
::
begin
(
rel_query
),
std
::
end
(
rel_query
)
);
}
return
res
;
}
...
...
@@ -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
,
std
::
string
&
path
,
const
char
*
base
,
size_t
baselen
,
const
char
*
uri
,
size_t
len
)
{
std
::
string
&
path
,
const
StringRef
&
base
,
const
StringRef
&
uri
)
{
int
rv
;
const
char
*
rel
,
*
relq
=
nullptr
;
size_t
rellen
,
relqlen
=
0
;
StringRef
rel
,
relq
;
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
(
uri
[
0
]
==
'/'
)
{
...
...
@@ -1496,22 +1493,20 @@ int construct_push_component(std::string &scheme, std::string &authority,
}
// treat link_url as relative URI.
auto
end
=
std
::
find
(
uri
,
uri
+
len
,
'#'
);
auto
q
=
std
::
find
(
uri
,
end
,
'?'
);
auto
end
=
std
::
find
(
std
::
begin
(
uri
),
std
::
end
(
uri
)
,
'#'
);
auto
q
=
std
::
find
(
std
::
begin
(
uri
)
,
end
,
'?'
);
rel
=
uri
;
rellen
=
q
-
uri
;
rel
=
StringRef
{
std
::
begin
(
uri
),
q
};
if
(
q
!=
end
)
{
relq
=
q
+
1
;
relqlen
=
end
-
relq
;
relq
=
StringRef
{
q
+
1
,
std
::
end
(
uri
)};
}
}
else
{
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
))
{
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
))
{
authority
+=
':'
;
authority
+=
util
::
utos
(
u
.
port
);
...
...
@@ -1520,22 +1515,18 @@ int construct_push_component(std::string &scheme, std::string &authority,
if
(
u
.
field_set
&
(
1
<<
UF_PATH
))
{
auto
&
f
=
u
.
field_data
[
UF_PATH
];
rel
=
uri
+
f
.
off
;
rellen
=
f
.
len
;
rel
=
StringRef
{
uri
.
c_str
()
+
f
.
off
,
f
.
len
};
}
else
{
rel
=
"/"
;
rellen
=
1
;
rel
=
StringRef
::
from_lit
(
"/"
);
}
if
(
u
.
field_set
&
(
1
<<
UF_QUERY
))
{
auto
&
f
=
u
.
field_data
[
UF_QUERY
];
relq
=
uri
+
f
.
off
;
relqlen
=
f
.
len
;
relq
=
StringRef
{
uri
.
c_str
()
+
f
.
off
,
f
.
len
};
}
}
path
=
http2
::
path_join
(
base
,
baselen
,
nullptr
,
0
,
rel
,
rellen
,
relq
,
relqlen
);
path
=
http2
::
path_join
(
base
,
StringRef
{},
rel
,
relq
);
return
0
;
}
...
...
src/http2.h
View file @
acbf38fd
...
...
@@ -297,16 +297,13 @@ struct LinkHeader {
// is ignored during parsing.
std
::
vector
<
LinkHeader
>
parse_link_header
(
const
char
*
src
,
size_t
len
);
// Constructs path by combining base path |base_path| of length
// |base_pathlen| with another path |rel_path| of length
// |rel_pathlen|. The base path and another path can have optional
// Constructs path by combining base path |base_path| with another
// path |rel_path|. The base path and another path can have optional
// query component. This function assumes |base_path| is normalized.
// In other words, it does not contain ".." or "." path components
// and starts with "/" if it is not empty.
std
::
string
path_join
(
const
char
*
base_path
,
size_t
base_pathlen
,
const
char
*
base_query
,
size_t
base_querylen
,
const
char
*
rel_path
,
size_t
rel_pathlen
,
const
char
*
rel_query
,
size_t
rel_querylen
);
std
::
string
path_join
(
const
StringRef
&
base
,
const
StringRef
&
base_query
,
const
StringRef
&
rel_path
,
const
StringRef
&
rel_query
);
// true if response has body, taking into account the request method
// and status code.
...
...
@@ -359,8 +356,7 @@ std::string normalize_path(InputIt first, InputIt last) {
}
result
.
append
(
first
,
last
);
}
return
path_join
(
nullptr
,
0
,
nullptr
,
0
,
result
.
c_str
(),
result
.
size
(),
nullptr
,
0
);
return
path_join
(
StringRef
{},
StringRef
{},
StringRef
{
result
},
StringRef
{});
}
template
<
typename
InputIt
>
...
...
@@ -384,14 +380,14 @@ std::string rewrite_clean_path(InputIt first, InputIt last) {
int
get_pure_path_component
(
const
char
**
base
,
size_t
*
baselen
,
const
std
::
string
&
uri
);
// Deduces scheme, authority and path from given |uri|
of length
//
|len|, and stores them in |scheme|, |authority|, and |path
|
//
respectively. If |uri| is relative path, path resolution is take
n
//
palce using path given in |base| of length |baselen|. This
//
function returns 0 if it
succeeds, or -1.
// Deduces scheme, authority and path from given |uri|
, and stores
//
them in |scheme|, |authority|, and |path| respectively. If |uri
|
//
is relative path, path resolution takes place using path given i
n
//
|base| of length |baselen|. This function returns 0 if it
// succeeds, or -1.
int
construct_push_component
(
std
::
string
&
scheme
,
std
::
string
&
authority
,
std
::
string
&
path
,
const
char
*
base
,
size_t
baselen
,
const
char
*
uri
,
size_t
len
);
std
::
string
&
path
,
const
StringRef
&
base
,
const
StringRef
&
uri
);
}
// namespace http2
...
...
src/http2_test.cc
View file @
acbf38fd
This diff is collapsed.
Click to expand it.
src/shrpx_http2_upstream.cc
View file @
acbf38fd
...
...
@@ -1755,9 +1755,8 @@ int Http2Upstream::prepare_push_promise(Downstream *downstream) {
const
std
::
string
*
scheme_ptr
,
*
authority_ptr
;
std
::
string
scheme
,
authority
,
path
;
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
baselen
,
link
.
uri
.
c_str
(),
link
.
uri
.
size
());
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
StringRef
{
base
,
baselen
},
link
.
uri
);
if
(
rv
!=
0
)
{
continue
;
}
...
...
@@ -1872,8 +1871,8 @@ int Http2Upstream::initiate_push(Downstream *downstream, const char *uri,
const
std
::
string
*
scheme_ptr
,
*
authority_ptr
;
std
::
string
scheme
,
authority
,
path
;
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
baselen
,
uri
,
len
);
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
StringRef
{
base
,
baselen
},
StringRef
{
uri
,
len
}
);
if
(
rv
!=
0
)
{
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