Unverified Commit 2953ed6f authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #464 from knowledge4igor/tests_and_improvements_in_response_line_step

Add tests for ResponseLineStep and tiny fixes
parents 95d49204 92220dd5
......@@ -229,10 +229,10 @@ namespace Private {
auto *response = static_cast<Response *>(message);
if (match_raw("HTTP/1.1", sizeof("HTTP/1.1") - 1, cursor)) {
if (match_raw("HTTP/1.1", strlen("HTTP/1.1"), cursor)) {
//response->version = Version::Http11;
}
else if (match_raw("HTTP/1.0", sizeof("HTTP/1.0") - 1, cursor)) {
else if (match_raw("HTTP/1.0", strlen("HTTP/1.0"), cursor)) {
}
else {
raise("Encountered invalid HTTP version");
......
#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);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment