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
Hide 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) {
...
@@ -1453,28 +1453,21 @@ StringRef to_method_string(int method_token) {
return
StringRef
{
http_method_str
(
static_cast
<
http_method
>
(
method_token
))};
return
StringRef
{
http_method_str
(
static_cast
<
http_method
>
(
method_token
))};
}
}
int
get_pure_path_component
(
const
char
**
base
,
size_t
*
baselen
,
StringRef
get_pure_path_component
(
const
std
::
string
&
uri
)
{
const
std
::
string
&
uri
)
{
int
rv
;
int
rv
;
http_parser_url
u
{};
http_parser_url
u
{};
rv
=
http_parser_parse_url
(
uri
.
c_str
(),
uri
.
size
(),
0
,
&
u
);
rv
=
http_parser_parse_url
(
uri
.
c_str
(),
uri
.
size
(),
0
,
&
u
);
if
(
rv
!=
0
)
{
if
(
rv
!=
0
)
{
return
-
1
;
return
StringRef
{}
;
}
}
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
];
*
base
=
uri
.
c_str
()
+
f
.
off
;
return
StringRef
{
uri
.
c_str
()
+
f
.
off
,
f
.
len
};
*
baselen
=
f
.
len
;
return
0
;
}
}
*
base
=
"/"
;
return
StringRef
::
from_lit
(
"/"
);
*
baselen
=
1
;
return
0
;
}
}
int
construct_push_component
(
std
::
string
&
scheme
,
std
::
string
&
authority
,
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) {
...
@@ -374,11 +374,10 @@ std::string rewrite_clean_path(InputIt first, InputIt last) {
return
path
;
return
path
;
}
}
// Stores path component of |uri| in *base. Its extracted length is
// Returns path component of |uri|. The returned path does not
// stored in *baselen. The extracted path does not include query
// include query component. This function returns empty string if it
// component. This function returns 0 if it succeeds, or -1.
// fails.
int
get_pure_path_component
(
const
char
**
base
,
size_t
*
baselen
,
StringRef
get_pure_path_component
(
const
std
::
string
&
uri
);
const
std
::
string
&
uri
);
// Deduces scheme, authority and path from given |uri|, and stores
// Deduces scheme, authority and path from given |uri|, and stores
// them in |scheme|, |authority|, and |path| respectively. If |uri|
// 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) {
...
@@ -866,32 +866,25 @@ void test_http2_rewrite_clean_path(void) {
}
}
void
test_http2_get_pure_path_component
(
void
)
{
void
test_http2_get_pure_path_component
(
void
)
{
const
char
*
base
;
size_t
len
;
std
::
string
path
;
std
::
string
path
;
path
=
"/"
;
path
=
"/"
;
CU_ASSERT
(
0
==
http2
::
get_pure_path_component
(
&
base
,
&
len
,
path
));
CU_ASSERT
(
"/"
==
http2
::
get_pure_path_component
(
path
));
CU_ASSERT
(
util
::
streq_l
(
"/"
,
base
,
len
));
path
=
"/foo"
;
path
=
"/foo"
;
CU_ASSERT
(
0
==
http2
::
get_pure_path_component
(
&
base
,
&
len
,
path
));
CU_ASSERT
(
"/foo"
==
http2
::
get_pure_path_component
(
path
));
CU_ASSERT
(
util
::
streq_l
(
"/foo"
,
base
,
len
));
path
=
"https://example.org/bar"
;
path
=
"https://example.org/bar"
;
CU_ASSERT
(
0
==
http2
::
get_pure_path_component
(
&
base
,
&
len
,
path
));
CU_ASSERT
(
"/bar"
==
http2
::
get_pure_path_component
(
path
));
CU_ASSERT
(
util
::
streq_l
(
"/bar"
,
base
,
len
));
path
=
"https://example.org/alpha?q=a"
;
path
=
"https://example.org/alpha?q=a"
;
CU_ASSERT
(
0
==
http2
::
get_pure_path_component
(
&
base
,
&
len
,
path
));
CU_ASSERT
(
"/alpha"
==
http2
::
get_pure_path_component
(
path
));
CU_ASSERT
(
util
::
streq_l
(
"/alpha"
,
base
,
len
));
path
=
"https://example.org/bravo?q=a#fragment"
;
path
=
"https://example.org/bravo?q=a#fragment"
;
CU_ASSERT
(
0
==
http2
::
get_pure_path_component
(
&
base
,
&
len
,
path
));
CU_ASSERT
(
"/bravo"
==
http2
::
get_pure_path_component
(
path
));
CU_ASSERT
(
util
::
streq_l
(
"/bravo"
,
base
,
len
));
path
=
"
\x01\x02
"
;
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
)
{
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) {
...
@@ -1734,14 +1734,12 @@ int Http2Upstream::on_downstream_reset(bool no_retry) {
int
Http2Upstream
::
prepare_push_promise
(
Downstream
*
downstream
)
{
int
Http2Upstream
::
prepare_push_promise
(
Downstream
*
downstream
)
{
int
rv
;
int
rv
;
const
char
*
base
;
size_t
baselen
;
const
auto
&
req
=
downstream
->
request
();
const
auto
&
req
=
downstream
->
request
();
const
auto
&
resp
=
downstream
->
response
();
const
auto
&
resp
=
downstream
->
response
();
rv
=
http2
::
get_pure_path_component
(
&
base
,
&
baselen
,
req
.
path
);
auto
base
=
http2
::
get_pure_path_component
(
req
.
path
);
if
(
rv
!=
0
)
{
if
(
base
.
empty
()
)
{
return
0
;
return
0
;
}
}
...
@@ -1755,8 +1753,8 @@ int Http2Upstream::prepare_push_promise(Downstream *downstream) {
...
@@ -1755,8 +1753,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
,
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
StringRef
{
base
,
baselen
},
link
.
uri
);
link
.
uri
);
if
(
rv
!=
0
)
{
if
(
rv
!=
0
)
{
continue
;
continue
;
}
}
...
@@ -1858,21 +1856,18 @@ int Http2Upstream::initiate_push(Downstream *downstream, const char *uri,
...
@@ -1858,21 +1856,18 @@ int Http2Upstream::initiate_push(Downstream *downstream, const char *uri,
return
0
;
return
0
;
}
}
const
char
*
base
;
size_t
baselen
;
const
auto
&
req
=
downstream
->
request
();
const
auto
&
req
=
downstream
->
request
();
rv
=
http2
::
get_pure_path_component
(
&
base
,
&
baselen
,
req
.
path
);
auto
base
=
http2
::
get_pure_path_component
(
req
.
path
);
if
(
rv
!=
0
)
{
if
(
base
.
empty
()
)
{
return
-
1
;
return
-
1
;
}
}
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
(
rv
=
http2
::
construct_push_component
(
scheme
,
authority
,
path
,
base
,
scheme
,
authority
,
path
,
StringRef
{
base
,
baselen
},
StringRef
{
uri
,
len
});
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