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
3f2b54cf
Commit
3f2b54cf
authored
Mar 04, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src: Refactor using StringRef
parent
acbf38fd
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
42 deletions
+22
-42
src/http2.cc
src/http2.cc
+4
-11
src/http2.h
src/http2.h
+4
-5
src/http2_test.cc
src/http2_test.cc
+6
-13
src/shrpx_http2_upstream.cc
src/shrpx_http2_upstream.cc
+8
-13
No files found.
src/http2.cc
View file @
3f2b54cf
...
...
@@ -1453,28 +1453,21 @@ StringRef to_method_string(int method_token) {
return
StringRef
{
http_method_str
(
static_cast
<
http_method
>
(
method_token
))};
}
int
get_pure_path_component
(
const
char
**
base
,
size_t
*
baselen
,
const
std
::
string
&
uri
)
{
StringRef
get_pure_path_component
(
const
std
::
string
&
uri
)
{
int
rv
;
http_parser_url
u
{};
rv
=
http_parser_parse_url
(
uri
.
c_str
(),
uri
.
size
(),
0
,
&
u
);
if
(
rv
!=
0
)
{
return
-
1
;
return
StringRef
{}
;
}
if
(
u
.
field_set
&
(
1
<<
UF_PATH
))
{
auto
&
f
=
u
.
field_data
[
UF_PATH
];
*
base
=
uri
.
c_str
()
+
f
.
off
;
*
baselen
=
f
.
len
;
return
0
;
return
StringRef
{
uri
.
c_str
()
+
f
.
off
,
f
.
len
};
}
*
base
=
"/"
;
*
baselen
=
1
;
return
0
;
return
StringRef
::
from_lit
(
"/"
);
}
int
construct_push_component
(
std
::
string
&
scheme
,
std
::
string
&
authority
,
...
...
src/http2.h
View file @
3f2b54cf
...
...
@@ -374,11 +374,10 @@ std::string rewrite_clean_path(InputIt first, InputIt last) {
return
path
;
}
// Stores path component of |uri| in *base. Its extracted length is
// stored in *baselen. The extracted path does not include query
// component. This function returns 0 if it succeeds, or -1.
int
get_pure_path_component
(
const
char
**
base
,
size_t
*
baselen
,
const
std
::
string
&
uri
);
// Returns path component of |uri|. The returned path does not
// include query component. This function returns empty string if it
// fails.
StringRef
get_pure_path_component
(
const
std
::
string
&
uri
);
// Deduces scheme, authority and path from given |uri|, and stores
// them in |scheme|, |authority|, and |path| respectively. If |uri|
...
...
src/http2_test.cc
View file @
3f2b54cf
...
...
@@ -866,32 +866,25 @@ void test_http2_rewrite_clean_path(void) {
}
void
test_http2_get_pure_path_component
(
void
)
{
const
char
*
base
;
size_t
len
;
std
::
string
path
;
path
=
"/"
;
CU_ASSERT
(
0
==
http2
::
get_pure_path_component
(
&
base
,
&
len
,
path
));
CU_ASSERT
(
util
::
streq_l
(
"/"
,
base
,
len
));
CU_ASSERT
(
"/"
==
http2
::
get_pure_path_component
(
path
));
path
=
"/foo"
;
CU_ASSERT
(
0
==
http2
::
get_pure_path_component
(
&
base
,
&
len
,
path
));
CU_ASSERT
(
util
::
streq_l
(
"/foo"
,
base
,
len
));
CU_ASSERT
(
"/foo"
==
http2
::
get_pure_path_component
(
path
));
path
=
"https://example.org/bar"
;
CU_ASSERT
(
0
==
http2
::
get_pure_path_component
(
&
base
,
&
len
,
path
));
CU_ASSERT
(
util
::
streq_l
(
"/bar"
,
base
,
len
));
CU_ASSERT
(
"/bar"
==
http2
::
get_pure_path_component
(
path
));
path
=
"https://example.org/alpha?q=a"
;
CU_ASSERT
(
0
==
http2
::
get_pure_path_component
(
&
base
,
&
len
,
path
));
CU_ASSERT
(
util
::
streq_l
(
"/alpha"
,
base
,
len
));
CU_ASSERT
(
"/alpha"
==
http2
::
get_pure_path_component
(
path
));
path
=
"https://example.org/bravo?q=a#fragment"
;
CU_ASSERT
(
0
==
http2
::
get_pure_path_component
(
&
base
,
&
len
,
path
));
CU_ASSERT
(
util
::
streq_l
(
"/bravo"
,
base
,
len
));
CU_ASSERT
(
"/bravo"
==
http2
::
get_pure_path_component
(
path
));
path
=
"
\x01\x02
"
;
CU_ASSERT
(
-
1
==
http2
::
get_pure_path_component
(
&
base
,
&
len
,
path
));
CU_ASSERT
(
""
==
http2
::
get_pure_path_component
(
path
));
}
void
test_http2_construct_push_component
(
void
)
{
...
...
src/shrpx_http2_upstream.cc
View file @
3f2b54cf
...
...
@@ -1734,14 +1734,12 @@ int Http2Upstream::on_downstream_reset(bool no_retry) {
int
Http2Upstream
::
prepare_push_promise
(
Downstream
*
downstream
)
{
int
rv
;
const
char
*
base
;
size_t
baselen
;
const
auto
&
req
=
downstream
->
request
();
const
auto
&
resp
=
downstream
->
response
();
rv
=
http2
::
get_pure_path_component
(
&
base
,
&
baselen
,
req
.
path
);
if
(
rv
!=
0
)
{
auto
base
=
http2
::
get_pure_path_component
(
req
.
path
);
if
(
base
.
empty
()
)
{
return
0
;
}
...
...
@@ -1755,8 +1753,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
,
StringRef
{
base
,
baselen
},
link
.
uri
);
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
link
.
uri
);
if
(
rv
!=
0
)
{
continue
;
}
...
...
@@ -1858,21 +1856,18 @@ int Http2Upstream::initiate_push(Downstream *downstream, const char *uri,
return
0
;
}
const
char
*
base
;
size_t
baselen
;
const
auto
&
req
=
downstream
->
request
();
rv
=
http2
::
get_pure_path_component
(
&
base
,
&
baselen
,
req
.
path
);
if
(
rv
!=
0
)
{
auto
base
=
http2
::
get_pure_path_component
(
req
.
path
);
if
(
base
.
empty
()
)
{
return
-
1
;
}
const
std
::
string
*
scheme_ptr
,
*
authority_ptr
;
std
::
string
scheme
,
authority
,
path
;
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
StringRef
{
base
,
baselen
},
StringRef
{
uri
,
len
});
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
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