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
b440f585
Commit
b440f585
authored
Feb 13, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: Use Header to store custom request/response header fields
parent
63a13ccb
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
32 additions
and
34 deletions
+32
-34
src/shrpx_config.cc
src/shrpx_config.cc
+8
-11
src/shrpx_config.h
src/shrpx_config.h
+4
-3
src/shrpx_config_test.cc
src/shrpx_config_test.cc
+12
-12
src/shrpx_http2_downstream_connection.cc
src/shrpx_http2_downstream_connection.cc
+1
-1
src/shrpx_http2_upstream.cc
src/shrpx_http2_upstream.cc
+1
-1
src/shrpx_http_downstream_connection.cc
src/shrpx_http_downstream_connection.cc
+2
-2
src/shrpx_https_upstream.cc
src/shrpx_https_upstream.cc
+2
-2
src/shrpx_spdy_upstream.cc
src/shrpx_spdy_upstream.cc
+2
-2
No files found.
src/shrpx_config.cc
View file @
b440f585
...
...
@@ -54,9 +54,7 @@
#include "shrpx_log.h"
#include "shrpx_ssl.h"
#include "shrpx_http.h"
#include "http2.h"
#include "util.h"
#include "template.h"
#include "base64.h"
namespace
shrpx
{
...
...
@@ -279,7 +277,7 @@ std::string read_passwd_from_file(const char *filename) {
return
line
;
}
std
::
pair
<
std
::
string
,
std
::
string
>
parse_header
(
const
char
*
optarg
)
{
Headers
::
value_type
parse_header
(
const
char
*
optarg
)
{
const
auto
*
colon
=
strchr
(
optarg
,
':'
);
if
(
colon
==
nullptr
||
colon
==
optarg
)
{
...
...
@@ -290,16 +288,15 @@ std::pair<std::string, std::string> parse_header(const char *optarg) {
for
(;
*
value
==
'\t'
||
*
value
==
' '
;
++
value
)
;
auto
p
=
std
::
make_pair
(
std
::
string
(
optarg
,
colon
),
std
::
string
(
value
,
strlen
(
value
)));
util
::
inp_strlower
(
p
.
first
);
auto
p
=
Header
(
std
::
string
(
optarg
,
colon
),
std
::
string
(
value
,
strlen
(
value
)));
util
::
inp_strlower
(
p
.
name
);
if
(
!
nghttp2_check_header_name
(
reinterpret_cast
<
const
uint8_t
*>
(
p
.
first
.
c_str
()),
p
.
first
.
size
())
||
reinterpret_cast
<
const
uint8_t
*>
(
p
.
name
.
c_str
()),
p
.
name
.
size
())
||
!
nghttp2_check_header_value
(
reinterpret_cast
<
const
uint8_t
*>
(
p
.
second
.
c_str
()),
p
.
second
.
size
()))
{
return
{
""
,
""
};
reinterpret_cast
<
const
uint8_t
*>
(
p
.
value
.
c_str
()),
p
.
value
.
size
()))
{
return
Header
();
}
return
p
;
...
...
@@ -2028,7 +2025,7 @@ int parse_config(const char *opt, const char *optarg,
case
SHRPX_OPTID_ADD_REQUEST_HEADER
:
case
SHRPX_OPTID_ADD_RESPONSE_HEADER
:
{
auto
p
=
parse_header
(
optarg
);
if
(
p
.
first
.
empty
())
{
if
(
p
.
name
.
empty
())
{
LOG
(
ERROR
)
<<
opt
<<
": invalid header field: "
<<
optarg
;
return
-
1
;
}
...
...
src/shrpx_config.h
View file @
b440f585
...
...
@@ -52,6 +52,7 @@
#include "shrpx_router.h"
#include "template.h"
#include "http2.h"
using
namespace
nghttp2
;
...
...
@@ -461,8 +462,8 @@ struct HttpConfig {
bool
strip_incoming
;
}
xff
;
std
::
vector
<
AltSvc
>
altsvcs
;
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
add_request_headers
;
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
add_response_headers
;
Headers
add_request_headers
;
Headers
add_response_headers
;
StringRef
server_name
;
size_t
request_header_field_buffer
;
size_t
max_request_header_fields
;
...
...
@@ -633,7 +634,7 @@ std::string read_passwd_from_file(const char *filename);
// like "NAME: VALUE". We require that NAME is non empty string. ":"
// is allowed at the start of the NAME, but NAME == ":" is not
// allowed. This function returns pair of NAME and VALUE.
std
::
pair
<
std
::
string
,
std
::
string
>
parse_header
(
const
char
*
optarg
);
Headers
::
value_type
parse_header
(
const
char
*
optarg
);
std
::
vector
<
LogFragment
>
parse_log_format
(
const
char
*
optarg
);
...
...
src/shrpx_config_test.cc
View file @
b440f585
...
...
@@ -38,32 +38,32 @@ namespace shrpx {
void
test_shrpx_config_parse_header
(
void
)
{
auto
p
=
parse_header
(
"a: b"
);
CU_ASSERT
(
"a"
==
p
.
first
);
CU_ASSERT
(
"b"
==
p
.
second
);
CU_ASSERT
(
"a"
==
p
.
name
);
CU_ASSERT
(
"b"
==
p
.
value
);
p
=
parse_header
(
"a: b"
);
CU_ASSERT
(
"a"
==
p
.
first
);
CU_ASSERT
(
"b"
==
p
.
second
);
CU_ASSERT
(
"a"
==
p
.
name
);
CU_ASSERT
(
"b"
==
p
.
value
);
p
=
parse_header
(
":a: b"
);
CU_ASSERT
(
p
.
first
.
empty
());
CU_ASSERT
(
p
.
name
.
empty
());
p
=
parse_header
(
"a: :b"
);
CU_ASSERT
(
"a"
==
p
.
first
);
CU_ASSERT
(
":b"
==
p
.
second
);
CU_ASSERT
(
"a"
==
p
.
name
);
CU_ASSERT
(
":b"
==
p
.
value
);
p
=
parse_header
(
": b"
);
CU_ASSERT
(
p
.
first
.
empty
());
CU_ASSERT
(
p
.
name
.
empty
());
p
=
parse_header
(
"alpha: bravo charlie"
);
CU_ASSERT
(
"alpha"
==
p
.
first
);
CU_ASSERT
(
"bravo charlie"
==
p
.
second
);
CU_ASSERT
(
"alpha"
==
p
.
name
);
CU_ASSERT
(
"bravo charlie"
==
p
.
value
);
p
=
parse_header
(
"a,: b"
);
CU_ASSERT
(
p
.
first
.
empty
());
CU_ASSERT
(
p
.
name
.
empty
());
p
=
parse_header
(
"a: b
\x0a
"
);
CU_ASSERT
(
p
.
first
.
empty
());
CU_ASSERT
(
p
.
name
.
empty
());
}
void
test_shrpx_config_parse_log_format
(
void
)
{
...
...
src/shrpx_http2_downstream_connection.cc
View file @
b440f585
...
...
@@ -422,7 +422,7 @@ int Http2DownstreamConnection::push_request_headers() {
}
for
(
auto
&
p
:
httpconf
.
add_request_headers
)
{
nva
.
push_back
(
http2
::
make_nv_nocopy
(
p
.
first
,
p
.
second
));
nva
.
push_back
(
http2
::
make_nv_nocopy
(
p
.
name
,
p
.
value
));
}
if
(
LOG_ENABLED
(
INFO
))
{
...
...
src/shrpx_http2_upstream.cc
View file @
b440f585
...
...
@@ -1436,7 +1436,7 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) {
}
for
(
auto
&
p
:
httpconf
.
add_response_headers
)
{
nva
.
push_back
(
http2
::
make_nv_nocopy
(
p
.
first
,
p
.
second
));
nva
.
push_back
(
http2
::
make_nv_nocopy
(
p
.
name
,
p
.
value
));
}
if
(
downstream
->
get_stream_id
()
%
2
==
0
)
{
...
...
src/shrpx_http_downstream_connection.cc
View file @
b440f585
...
...
@@ -418,9 +418,9 @@ int HttpDownstreamConnection::push_request_headers() {
}
for
(
auto
&
p
:
httpconf
.
add_request_headers
)
{
buf
->
append
(
p
.
first
);
buf
->
append
(
p
.
name
);
buf
->
append
(
": "
);
buf
->
append
(
p
.
second
);
buf
->
append
(
p
.
value
);
buf
->
append
(
"
\r\n
"
);
}
...
...
src/shrpx_https_upstream.cc
View file @
b440f585
...
...
@@ -1022,9 +1022,9 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream) {
}
for
(
auto
&
p
:
httpconf
.
add_response_headers
)
{
buf
->
append
(
p
.
first
);
buf
->
append
(
p
.
name
);
buf
->
append
(
": "
);
buf
->
append
(
p
.
second
);
buf
->
append
(
p
.
value
);
buf
->
append
(
"
\r\n
"
);
}
...
...
src/shrpx_spdy_upstream.cc
View file @
b440f585
...
...
@@ -1064,8 +1064,8 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream) {
}
for
(
auto
&
p
:
httpconf
.
add_response_headers
)
{
nv
[
hdidx
++
]
=
p
.
first
.
c_str
();
nv
[
hdidx
++
]
=
p
.
second
.
c_str
();
nv
[
hdidx
++
]
=
p
.
name
.
c_str
();
nv
[
hdidx
++
]
=
p
.
value
.
c_str
();
}
nv
[
hdidx
++
]
=
0
;
...
...
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