-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_http_parser.cpp
More file actions
29 lines (24 loc) · 873 Bytes
/
Copy pathtest_http_parser.cpp
File metadata and controls
29 lines (24 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "../doctest/doctest/doctest.h"
#include "../src/http/http.hpp"
#include "../src/netlib.hpp"
using namespace std::chrono_literals;
extern uint16_t test_port;
TEST_CASE("Test HTTP response parser")
{
netlib::http::http_response resp;
std::string raw_response = "HTTP/1.1 200 OK\r\n"
"Content-Type: text/html; charset=UTF-8\r\n"
"Content-Length: 1256\r\n"
"\r\n\r\n"
"TEST";
CHECK_FALSE(resp.from_raw_response(raw_response));
CHECK_EQ(resp.version.first, 1);
CHECK_EQ(resp.version.second, 1);
CHECK_EQ(resp.response_code, 200);
CHECK_EQ(resp.headers.size(), 2);
CHECK_EQ(resp.headers[0].first, "Content-Type");
CHECK_EQ(resp.headers[1].first, "Content-Length");
CHECK_EQ(resp.headers[0].second, " text/html; charset=UTF-8");
CHECK_EQ(resp.headers[1].second, " 1256");
CHECK_EQ(resp.body, "TEST");
}