Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
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
pistache
Commits
f4f6217e
Commit
f4f6217e
authored
Oct 29, 2019
by
Adam Burgess
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Cookie/Set-Cookie headers case-insensitive
parent
d72ee8c7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
2 deletions
+38
-2
include/pistache/http_headers.h
include/pistache/http_headers.h
+2
-0
src/common/http.cc
src/common/http.cc
+2
-2
src/common/http_headers.cc
src/common/http_headers.cc
+8
-0
tests/headers_test.cc
tests/headers_test.cc
+26
-0
No files found.
include/pistache/http_headers.h
View file @
f4f6217e
...
...
@@ -28,6 +28,8 @@ struct LowercaseHash {
}
};
bool
LowercaseEqualStatic
(
const
std
::
string
&
dynamic
,
const
std
::
string
&
statik
);
struct
LowercaseEqual
{
bool
operator
()(
const
std
::
string
&
left
,
const
std
::
string
&
right
)
const
{
return
std
::
equal
(
left
.
begin
(),
left
.
end
(),
right
.
begin
(),
right
.
end
(),
...
...
src/common/http.cc
View file @
f4f6217e
...
...
@@ -290,11 +290,11 @@ namespace Private {
if
(
!
cursor
.
advance
(
1
))
return
State
::
Again
;
}
if
(
name
==
"Cookie"
)
{
if
(
Header
::
LowercaseEqualStatic
(
name
,
"cookie"
)
)
{
message
->
cookies_
.
removeAllCookies
();
// removing existing cookies before re-adding them.
message
->
cookies_
.
addFromRaw
(
cursor
.
offset
(
start
),
cursor
.
diff
(
start
));
}
else
if
(
name
==
"Set-Cookie"
)
{
else
if
(
Header
::
LowercaseEqualStatic
(
name
,
"set-cookie"
)
)
{
message
->
cookies_
.
add
(
Cookie
::
fromRaw
(
cursor
.
offset
(
start
),
cursor
.
diff
(
start
)));
}
...
...
src/common/http_headers.cc
View file @
f4f6217e
...
...
@@ -41,6 +41,14 @@ toLowercase(std::string str) {
return
str
;
}
bool
LowercaseEqualStatic
(
const
std
::
string
&
dynamic
,
const
std
::
string
&
statik
)
{
return
std
::
equal
(
dynamic
.
begin
(),
dynamic
.
end
(),
statik
.
begin
(),
statik
.
end
(),
[]
(
const
char
&
a
,
const
char
&
b
)
{
return
std
::
tolower
(
a
)
==
b
;
});
}
Registry
&
Registry
::
instance
()
{
static
Registry
instance
;
...
...
tests/headers_test.cc
View file @
f4f6217e
...
...
@@ -713,3 +713,29 @@ TEST(headers_test, raw_headers_are_case_insensitive)
ASSERT_FALSE
(
request
.
headers
().
tryGetRaw
(
"Custom-Header"
).
isEmpty
());
ASSERT_FALSE
(
request
.
headers
().
tryGetRaw
(
"custom-header"
).
isEmpty
());
}
TEST
(
headers_test
,
cookie_headers_are_case_insensitive
)
{
{
std
::
string
line
=
"cookie: x=y
\r\n
"
;
Pistache
::
RawStreamBuf
<>
buf
(
&
line
[
0
],
line
.
size
());
Pistache
::
StreamCursor
cursor
(
&
buf
);
Pistache
::
Http
::
Request
request
;
Pistache
::
Http
::
Private
::
HeadersStep
step
(
&
request
);
step
.
apply
(
cursor
);
ASSERT_TRUE
(
request
.
cookies
().
has
(
"x"
));
}
{
std
::
string
line
=
"set-cookie: x=y
\r\n
"
;
Pistache
::
RawStreamBuf
<>
buf
(
&
line
[
0
],
line
.
size
());
Pistache
::
StreamCursor
cursor
(
&
buf
);
Pistache
::
Http
::
Request
request
;
Pistache
::
Http
::
Private
::
HeadersStep
step
(
&
request
);
step
.
apply
(
cursor
);
ASSERT_TRUE
(
request
.
cookies
().
has
(
"x"
));
}
}
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