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
b85924bf
Commit
b85924bf
authored
Oct 02, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: Use BlockAllocator to encode alt-svc token
parent
19707aac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
16 deletions
+24
-16
src/shrpx_https_upstream.cc
src/shrpx_https_upstream.cc
+6
-4
src/util.cc
src/util.cc
+8
-7
src/util.h
src/util.h
+1
-1
src/util_test.cc
src/util_test.cc
+9
-4
No files found.
src/shrpx_https_upstream.cc
View file @
b85924bf
...
...
@@ -960,8 +960,10 @@ std::unique_ptr<Downstream> HttpsUpstream::pop_downstream() {
}
namespace
{
void
write_altsvc
(
DefaultMemchunks
*
buf
,
const
AltSvc
&
altsvc
)
{
buf
->
append
(
util
::
percent_encode_token
(
altsvc
.
protocol_id
));
void
write_altsvc
(
DefaultMemchunks
*
buf
,
BlockAllocator
&
balloc
,
const
AltSvc
&
altsvc
)
{
buf
->
append
(
util
::
percent_encode_token
(
balloc
,
StringRef
{
altsvc
.
protocol_id
}));
buf
->
append
(
"=
\"
"
);
buf
->
append
(
util
::
quote_string
(
altsvc
.
host
));
buf
->
append
(
":"
);
...
...
@@ -1073,10 +1075,10 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream) {
buf
->
append
(
"Alt-Svc: "
);
auto
&
altsvcs
=
httpconf
.
altsvcs
;
write_altsvc
(
buf
,
altsvcs
[
0
]);
write_altsvc
(
buf
,
downstream
->
get_block_allocator
(),
altsvcs
[
0
]);
for
(
size_t
i
=
1
;
i
<
altsvcs
.
size
();
++
i
)
{
buf
->
append
(
", "
);
write_altsvc
(
buf
,
altsvcs
[
i
]);
write_altsvc
(
buf
,
downstream
->
get_block_allocator
(),
altsvcs
[
i
]);
}
buf
->
append
(
"
\r\n
"
);
}
...
...
src/util.cc
View file @
b85924bf
...
...
@@ -131,11 +131,10 @@ bool in_attr_char(char c) {
std
::
find
(
std
::
begin
(
bad
),
std
::
end
(
bad
),
c
)
==
std
::
end
(
bad
);
}
std
::
string
percent_encode_token
(
const
std
::
string
&
target
)
{
std
::
string
dest
;
dest
.
resize
(
target
.
size
()
*
3
);
auto
p
=
std
::
begin
(
dest
);
StringRef
percent_encode_token
(
BlockAllocator
&
balloc
,
const
StringRef
&
target
)
{
auto
iov
=
make_byte_ref
(
balloc
,
target
.
size
()
*
3
+
1
);
auto
p
=
iov
.
base
;
for
(
auto
first
=
std
::
begin
(
target
);
first
!=
std
::
end
(
target
);
++
first
)
{
uint8_t
c
=
*
first
;
...
...
@@ -149,8 +148,10 @@ std::string percent_encode_token(const std::string &target) {
*
p
++
=
UPPER_XDIGITS
[
c
>>
4
];
*
p
++
=
UPPER_XDIGITS
[(
c
&
0x0f
)];
}
dest
.
resize
(
p
-
std
::
begin
(
dest
));
return
dest
;
*
p
=
'\0'
;
return
StringRef
{
iov
.
base
,
p
};
}
uint32_t
hex_to_uint
(
char
c
)
{
...
...
src/util.h
View file @
b85924bf
...
...
@@ -129,7 +129,7 @@ std::string percent_decode(InputIt first, InputIt last) {
StringRef
percent_decode
(
BlockAllocator
&
balloc
,
const
StringRef
&
src
);
// Percent encode |target| if character is not in token or '%'.
std
::
string
percent_encode_token
(
const
std
::
string
&
target
);
StringRef
percent_encode_token
(
BlockAllocator
&
balloc
,
const
StringRef
&
target
);
// Returns quotedString version of |target|. Currently, this function
// just replace '"' with '\"'.
...
...
src/util_test.cc
View file @
b85924bf
...
...
@@ -134,10 +134,15 @@ void test_util_to_token68(void) {
}
void
test_util_percent_encode_token
(
void
)
{
CU_ASSERT
(
"h2"
==
util
::
percent_encode_token
(
"h2"
));
CU_ASSERT
(
"h3~"
==
util
::
percent_encode_token
(
"h3~"
));
CU_ASSERT
(
"100%25"
==
util
::
percent_encode_token
(
"100%"
));
CU_ASSERT
(
"http%202"
==
util
::
percent_encode_token
(
"http 2"
));
BlockAllocator
balloc
(
4096
,
4096
);
CU_ASSERT
(
"h2"
==
util
::
percent_encode_token
(
balloc
,
StringRef
::
from_lit
(
"h2"
)));
CU_ASSERT
(
"h3~"
==
util
::
percent_encode_token
(
balloc
,
StringRef
::
from_lit
(
"h3~"
)));
CU_ASSERT
(
"100%25"
==
util
::
percent_encode_token
(
balloc
,
StringRef
::
from_lit
(
"100%"
)));
CU_ASSERT
(
"http%202"
==
util
::
percent_encode_token
(
balloc
,
StringRef
::
from_lit
(
"http 2"
)));
}
void
test_util_percent_encode_path
(
void
)
{
...
...
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