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
28469125
Commit
28469125
authored
Feb 28, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: Use StringRef for http::create_forwarded parameter
parent
124d4c9f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
35 additions
and
28 deletions
+35
-28
src/shrpx_client_handler.cc
src/shrpx_client_handler.cc
+4
-4
src/shrpx_client_handler.h
src/shrpx_client_handler.h
+2
-2
src/shrpx_http.cc
src/shrpx_http.cc
+2
-3
src/shrpx_http.h
src/shrpx_http.h
+2
-2
src/shrpx_http2_downstream_connection.cc
src/shrpx_http2_downstream_connection.cc
+3
-3
src/shrpx_http_downstream_connection.cc
src/shrpx_http_downstream_connection.cc
+3
-3
src/shrpx_http_test.cc
src/shrpx_http_test.cc
+19
-11
No files found.
src/shrpx_client_handler.cc
View file @
28469125
...
...
@@ -1138,18 +1138,18 @@ int ClientHandler::proxy_protocol_read() {
return
on_proxy_protocol_finish
();
}
StringRef
ClientHandler
::
get_forwarded_by
()
{
StringRef
ClientHandler
::
get_forwarded_by
()
const
{
auto
&
fwdconf
=
get_config
()
->
http
.
forwarded
;
if
(
fwdconf
.
by_node_type
==
FORWARDED_NODE_OBFUSCATED
)
{
return
StringRef
(
fwdconf
.
by_obfuscated
);
}
return
StringRef
(
faddr_
->
hostport
)
;
return
StringRef
{
faddr_
->
hostport
}
;
}
const
std
::
string
&
ClientHandler
::
get_forwarded_for
()
const
{
return
forwarded_for_
;
StringRef
ClientHandler
::
get_forwarded_for
()
const
{
return
StringRef
{
forwarded_for_
}
;
}
}
// namespace shrpx
src/shrpx_client_handler.h
View file @
28469125
...
...
@@ -135,10 +135,10 @@ public:
// Returns string suitable for use in "by" parameter of Forwarded
// header field.
StringRef
get_forwarded_by
();
StringRef
get_forwarded_by
()
const
;
// Returns string suitable for use in "for" parameter of Forwarded
// header field.
const
std
::
string
&
get_forwarded_for
()
const
;
StringRef
get_forwarded_for
()
const
;
private:
Connection
conn_
;
...
...
src/shrpx_http.cc
View file @
28469125
...
...
@@ -62,9 +62,8 @@ std::string create_via_header_value(int major, int minor) {
}
std
::
string
create_forwarded
(
int
params
,
const
StringRef
&
node_by
,
const
std
::
string
&
node_for
,
const
std
::
string
&
host
,
const
std
::
string
&
proto
)
{
const
StringRef
&
node_for
,
const
StringRef
&
host
,
const
StringRef
&
proto
)
{
std
::
string
res
;
if
((
params
&
FORWARDED_BY
)
&&
!
node_by
.
empty
())
{
// This must be quoted-string unless it is obfuscated version
...
...
src/shrpx_http.h
View file @
28469125
...
...
@@ -43,8 +43,8 @@ std::string create_via_header_value(int major, int minor);
// |params| is bitwise-OR of zero or more of shrpx_forwarded_param
// defined in shrpx_config.h.
std
::
string
create_forwarded
(
int
params
,
const
StringRef
&
node_by
,
const
std
::
string
&
node_for
,
const
std
::
string
&
host
,
const
std
::
string
&
proto
);
const
StringRef
&
node_for
,
const
StringRef
&
host
,
const
StringRef
&
proto
);
// Adds ANSI color codes to HTTP headers |hdrs|.
std
::
string
colorizeHeaders
(
const
char
*
hdrs
);
...
...
src/shrpx_http2_downstream_connection.cc
View file @
28469125
...
...
@@ -359,9 +359,9 @@ int Http2DownstreamConnection::push_request_headers() {
params
&=
~
FORWARDED_PROTO
;
}
auto
value
=
http
::
create_forwarded
(
params
,
handler
->
get_forwarded_by
(),
handler
->
get_forwarded_for
(),
req
.
authority
,
req
.
scheme
);
auto
value
=
http
::
create_forwarded
(
params
,
handler
->
get_forwarded_by
(),
handler
->
get_forwarded_for
(),
StringRef
{
req
.
authority
},
StringRef
{
req
.
scheme
}
);
if
(
fwd
||
!
value
.
empty
())
{
if
(
fwd
)
{
forwarded_value
=
fwd
->
value
;
...
...
src/shrpx_http_downstream_connection.cc
View file @
28469125
...
...
@@ -366,9 +366,9 @@ int HttpDownstreamConnection::push_request_headers() {
params
&=
~
FORWARDED_PROTO
;
}
auto
value
=
http
::
create_forwarded
(
params
,
handler
->
get_forwarded_by
(),
handler
->
get_forwarded_for
(),
req
.
authority
,
req
.
scheme
);
auto
value
=
http
::
create_forwarded
(
params
,
handler
->
get_forwarded_by
(),
handler
->
get_forwarded_for
(),
StringRef
{
req
.
authority
},
StringRef
{
req
.
scheme
}
);
if
(
fwd
||
!
value
.
empty
())
{
buf
->
append
(
"Forwarded: "
);
if
(
fwd
)
{
...
...
src/shrpx_http_test.cc
View file @
28469125
...
...
@@ -43,25 +43,33 @@ void test_shrpx_http_create_forwarded(void) {
http
::
create_forwarded
(
FORWARDED_BY
|
FORWARDED_FOR
|
FORWARDED_HOST
|
FORWARDED_PROTO
,
StringRef
::
from_lit
(
"example.com:3000"
),
"[::1]"
,
"www.example.com"
,
"https"
));
StringRef
::
from_lit
(
"[::1]"
),
StringRef
::
from_lit
(
"www.example.com"
),
StringRef
::
from_lit
(
"https"
)));
CU_ASSERT
(
"for=192.168.0.1"
==
http
::
create_forwarded
(
FORWARDED_FOR
,
StringRef
::
from_lit
(
"alpha"
),
"192.168.0.1"
,
"bravo"
,
"charlie"
));
StringRef
::
from_lit
(
"192.168.0.1"
),
StringRef
::
from_lit
(
"bravo"
),
StringRef
::
from_lit
(
"charlie"
)));
CU_ASSERT
(
"by=_hidden;for=
\"
[::1]
\"
"
==
http
::
create_forwarded
(
FORWARDED_BY
|
FORWARDED_FOR
,
StringRef
::
from_lit
(
"_hidden"
),
"[::1]"
,
""
,
""
));
http
::
create_forwarded
(
FORWARDED_BY
|
FORWARDED_FOR
,
StringRef
::
from_lit
(
"_hidden"
),
StringRef
::
from_lit
(
"[::1]"
),
StringRef
::
from_lit
(
""
),
StringRef
::
from_lit
(
""
)));
CU_ASSERT
(
"by=
\"
[::1]
\"
;for=_hidden"
==
http
::
create_forwarded
(
FORWARDED_BY
|
FORWARDED_FOR
,
StringRef
::
from_lit
(
"[::1]"
),
"_hidden"
,
""
,
""
));
http
::
create_forwarded
(
FORWARDED_BY
|
FORWARDED_FOR
,
StringRef
::
from_lit
(
"[::1]"
),
StringRef
::
from_lit
(
"_hidden"
),
StringRef
::
from_lit
(
""
),
StringRef
::
from_lit
(
""
)));
CU_ASSERT
(
""
==
http
::
create_forwarded
(
FORWARDED_BY
|
FORWARDED_FOR
|
FORWARDED_HOST
|
FORWARDED_PROTO
,
StringRef
::
from_lit
(
""
),
""
,
""
,
""
));
CU_ASSERT
(
""
==
http
::
create_forwarded
(
FORWARDED_BY
|
FORWARDED_FOR
|
FORWARDED_HOST
|
FORWARDED_PROTO
,
StringRef
::
from_lit
(
""
),
StringRef
::
from_lit
(
""
),
StringRef
::
from_lit
(
""
),
StringRef
::
from_lit
(
""
)));
}
}
// namespace shrpx
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