Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
8ec657ab
Commit
8ec657ab
authored
Jan 26, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add convenience versions of HttpHeaders::set() and add() that take ownership.
parent
2c15b603
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
http.c++
c++/src/kj/compat/http.c++
+16
-0
http.h
c++/src/kj/compat/http.h
+7
-2
No files found.
c++/src/kj/compat/http.c++
View file @
8ec657ab
...
...
@@ -328,6 +328,11 @@ void HttpHeaders::set(HttpHeaderId id, kj::StringPtr value) {
indexedHeaders
[
id
.
id
]
=
value
;
}
void
HttpHeaders
::
set
(
HttpHeaderId
id
,
kj
::
String
&&
value
)
{
set
(
id
,
kj
::
StringPtr
(
value
));
takeOwnership
(
kj
::
mv
(
value
));
}
void
HttpHeaders
::
add
(
kj
::
StringPtr
name
,
kj
::
StringPtr
value
)
{
requireValidHeaderName
(
name
);
requireValidHeaderValue
(
value
);
...
...
@@ -336,6 +341,17 @@ void HttpHeaders::add(kj::StringPtr name, kj::StringPtr value) {
"can't set connection-level headers on HttpHeaders"
,
name
,
value
)
{
break
;
}
}
void
HttpHeaders
::
add
(
kj
::
StringPtr
name
,
kj
::
String
&&
value
)
{
add
(
name
,
kj
::
StringPtr
(
value
));
takeOwnership
(
kj
::
mv
(
value
));
}
void
HttpHeaders
::
add
(
kj
::
String
&&
name
,
kj
::
String
&&
value
)
{
add
(
kj
::
StringPtr
(
name
),
kj
::
StringPtr
(
value
));
takeOwnership
(
kj
::
mv
(
name
));
takeOwnership
(
kj
::
mv
(
value
));
}
kj
::
Maybe
<
uint
>
HttpHeaders
::
addNoCheck
(
kj
::
StringPtr
name
,
kj
::
StringPtr
value
)
{
KJ_IF_MAYBE
(
id
,
table
->
stringToId
(
name
))
{
if
(
id
->
id
>
CONNECTION_HEADER_THRESHOLD
)
{
...
...
c++/src/kj/compat/http.h
View file @
8ec657ab
...
...
@@ -254,16 +254,23 @@ public:
// to IDs in the header table. Both inputs are of type kj::StringPtr.
void
set
(
HttpHeaderId
id
,
kj
::
StringPtr
value
);
void
set
(
HttpHeaderId
id
,
kj
::
String
&&
value
);
// Sets a header value, overwriting the existing value.
//
// The String&& version is equivalent to calling the other version followed by takeOwnership().
//
// WARNING: It is the caller's responsibility to ensure that `value` remains valid until the
// HttpHeaders object is destroyed. This allows string literals to be passed without making a
// copy, but complicates the use of dynamic values. Hint: Consider using `takeOwnership()`.
void
add
(
kj
::
StringPtr
name
,
kj
::
StringPtr
value
);
void
add
(
kj
::
StringPtr
name
,
kj
::
String
&&
value
);
void
add
(
kj
::
String
&&
name
,
kj
::
String
&&
value
);
// Append a header. `name` will be looked up in the header table, but if it's not mapped, the
// header will be added to the list of unmapped headers.
//
// The String&& versions are equivalent to calling the other version followed by takeOwnership().
//
// WARNING: It is the caller's responsibility to ensure that `name` and `value` remain valid
// until the HttpHeaders object is destroyed. This allows string literals to be passed without
// making a copy, but complicates the use of dynamic values. Hint: Consider using
...
...
@@ -280,8 +287,6 @@ public:
void
takeOwnership
(
HttpHeaders
&&
otherHeaders
);
// Takes overship of a string so that it lives until the HttpHeaders object is destroyed. Useful
// when you've passed a dynamic value to set() or add() or parse*().
//
// TODO(soon): Is takeOwnership() actually needed?
struct
ConnectionHeaders
{
// These headers govern details of the specific HTTP connection or framing of the content.
...
...
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