-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_request.h
More file actions
56 lines (48 loc) · 1.54 KB
/
http_request.h
File metadata and controls
56 lines (48 loc) · 1.54 KB
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
46
47
48
49
50
51
52
53
54
55
56
#include "http_parser.h"
#include <bits/stdc++.h>
using namespace std;
struct http_request {
enum request_status {
REQUEST_INVALID,
REQUEST_VALID
};
http_request(const string &s);
std::map<std::string, std::string> get_headers();
std::string get_url();
std::string get_method();
std::string get_body();
std::string get_path();
std::string get_query_string();
bool is_valid();
bool is_multipart();
const vector<std::string>& get_multipart_data();
private:
char *m_data = nullptr;
int m_len = 0;
bool m_request_status = REQUEST_INVALID;
using self_type = http_request;
http_parser m_parse;
http_parser_settings m_settings;
std::string m_latest_field;
std::string m_url;
std::string m_method;
std::string m_path;
std::string m_query_string;
std::map<std::string, std::string> m_headers;
std::string m_body_buf;
bool m_is_multipart;
std::string m_multipart_boundary;
vector<string> m_multipart_data;
void set_header(const std::string &value);
void set_latest_field(std::string);
void set_url(std::string);
void set_method(std::string);
void append_body(std::string);
void set_request_status(request_status);
static int on_header_field_cb(http_parser *parser, const char *buf, size_t len);
static int on_url_cb(http_parser *parser, const char *buf, size_t len);
static int on_header_value_cb(http_parser *parser, const char *buf, size_t len);
static int on_headers_complete_cb(http_parser *parser);
static int on_body_cb(http_parser *parser, const char *buf, size_t len);
static int on_message_complete_cb(http_parser *parser);
};