-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhttp.hpp
45 lines (36 loc) · 1.01 KB
/
http.hpp
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#include <string>
#include <map>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdint>
#include <sys/utsname.h>
struct http_request_t {
enum {
GET, POST, PUT, OPTIONS,
DELETE, UNKNOWN // etc
} request_method;
std::string request_path;
std::string http_version;
std::map<std::string, std::vector<std::string>> headers;
http_request_t(const uint8_t *const, const ssize_t);
void parse_http_method(std::stringstream &);
void parse_http_path(std::stringstream &);
void parse_http_version(std::stringstream &);
void parse_http_headers(std::stringstream &);
};
struct http_response_t {
int status_code;
std::string status_text;
std::map<std::string, std::vector<std::string>> headers;
std::string body;
http_response_t(const int);
void http_status_code_to_status_text();
void initialize_response_headers();
void append_header_date();
void append_header_connection();
void append_header_server();
std::string to_response();
};