-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHTTPParser.h
57 lines (47 loc) · 1.56 KB
/
HTTPParser.h
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
57
#ifndef _HTTP_PARSER_H_H
#define _HTTP_PARSER_H_H
#include "DataBuffer.h"
#include <deque>
#include <string>
#include "http-parser/http_parser.h"
class HTTPHeader
{
public:
enum HeaderParsingState
{
REPORTED_NONE = 0,
REPORTED_FIELD,
REPORTED_VALUE
};
std::string field;
std::string value;
};
class HTTPParser
{
public:
bool _headers_complete;
bool _body_complete;
std::deque<HTTPHeader *> _headers;
DataBuffer _body;
std::string _url;
std::string _method;
std::string _http_version;
int _response_status_code;
public:
HTTPParser(bool request);
size_t process_data(const char * data, size_t data_size);
static int request_on_message_begin(http_parser * parser);
static int request_on_headers_complete(http_parser * parser);
static int request_on_message_complete(http_parser * parser);
static int request_on_url(http_parser * parser, const char* at, size_t length);
static int request_on_header_field(http_parser * parser, const char* at, size_t length);
static int request_on_header_value(http_parser * parser, const char* at, size_t length);
static int request_on_body(http_parser * parser, const char* at, size_t length);
private:
HTTPParser() : _body(0) {}
http_parser_settings _settings;
http_parser _parser;
HTTPHeader::HeaderParsingState _header_parsing_state;
std::string _last_reported_field;
};
#endif // _HTTP_PARSER_H_H