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
c98600ca
Commit
c98600ca
authored
Feb 24, 2019
by
knowledge4igor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for ResponseLineStep and tiny fixes
parent
95d49204
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
4 deletions
+37
-4
src/common/http.cc
src/common/http.cc
+2
-2
tests/http_parsing_test.cc
tests/http_parsing_test.cc
+35
-2
No files found.
src/common/http.cc
View file @
c98600ca
...
...
@@ -229,10 +229,10 @@ namespace Private {
auto
*
response
=
static_cast
<
Response
*>
(
message
);
if
(
match_raw
(
"HTTP/1.1"
,
s
izeof
(
"HTTP/1.1"
)
-
1
,
cursor
))
{
if
(
match_raw
(
"HTTP/1.1"
,
s
trlen
(
"HTTP/1.1"
)
,
cursor
))
{
//response->version = Version::Http11;
}
else
if
(
match_raw
(
"HTTP/1.0"
,
s
izeof
(
"HTTP/1.0"
)
-
1
,
cursor
))
{
else
if
(
match_raw
(
"HTTP/1.0"
,
s
trlen
(
"HTTP/1.0"
)
,
cursor
))
{
}
else
{
raise
(
"Encountered invalid HTTP version"
);
...
...
tests/http_parsing_test.cc
View file @
c98600ca
#include "gtest/gtest.h"
#include <pistache/http.h>
#include <pistache/stream.h>
using
namespace
Pistache
;
...
...
@@ -9,7 +10,7 @@ TEST(http_parsing_test, should_parse_http_request_in_two_packets_issue_160)
{
Http
::
Private
::
Parser
<
Http
::
Request
>
parser
;
auto
feed
=
[
&
](
const
char
*
data
)
auto
feed
=
[
&
parser
](
const
char
*
data
)
{
parser
.
feed
(
data
,
std
::
strlen
(
data
));
};
...
...
@@ -31,4 +32,36 @@ TEST(http_parsing_test, should_parse_http_request_in_two_packets_issue_160)
// Finally, we finish the body
feed
(
"HELLO"
);
ASSERT_EQ
(
parser
.
parse
(),
Http
::
Private
::
State
::
Done
);
}
\ No newline at end of file
}
TEST
(
http_parsing_test
,
succ_response_line_step
)
{
Http
::
Response
response
;
Http
::
Private
::
ResponseLineStep
step
(
&
response
);
std
::
string
line
(
"HTTP/1.1 200 OK
\r\n
"
);
RawStreamBuf
buf
(
&
line
[
0
],
line
.
size
());
StreamCursor
cursor
(
&
buf
);
Http
::
Private
::
State
state
=
step
.
apply
(
cursor
);
ASSERT_EQ
(
state
,
Http
::
Private
::
State
::
Next
);
ASSERT_EQ
(
response
.
code
(),
Http
::
Code
::
Ok
);
}
TEST
(
http_parsing_test
,
error_response_line_step
)
{
std
::
vector
<
std
::
string
>
lines
=
{
"HTTP/ABC.DEF 200 OK
\r\n
"
,
"HTTP/1.1200 OK
\r\n
"
,
"HTTP/ABC.DEF 200
\r\n
"
};
for
(
auto
&
line
:
lines
)
{
Http
::
Response
response
;
Http
::
Private
::
ResponseLineStep
step
(
&
response
);
RawStreamBuf
buf
(
&
line
[
0
],
line
.
size
());
StreamCursor
cursor
(
&
buf
);
ASSERT_THROW
(
step
.
apply
(
cursor
),
Http
::
HttpError
);
}
}
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