forked from nodejs/http-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_parser.h
64 lines (46 loc) · 1.33 KB
/
http_parser.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
58
59
60
61
62
63
64
#ifndef HTTP_PARSER_CXX_H_
#define HTTP_PARSER_CXX_H_
#include <stdio.h>
#include <string>
#include <functional>
#include <unordered_map>
#include "parser_c/http_parser.h"
#include "http_message.h"
namespace http {
#define DEF_HTTP_CB(funcName) \
static int funcName##_(http_parser * parser) { \
HttpParser *p = (HttpParser*)parser->data; \
return p->funcName(); \
} \
int funcName();
#define DEF_HTTP_DATA_CB(funcName) \
static int funcName##_(http_parser * parser, \
const char *at, size_t length) { \
HttpParser *p = (HttpParser*)parser->data; \
return p->funcName(at, length); \
} \
int funcName(const char *, size_t);
#define GET_DEF_CB_NAME(funcName) funcName##_
class HttpParser {
public:
typedef std::function<void(bool)> CompleteCallback;
void Init(HttpMessage* msg, http_parser_type type, CompleteCallback cb);
void Execute(const char* ptr, int size);
void Clear();
DEF_HTTP_CB(OnBegin);
DEF_HTTP_CB(OnComplete);
DEF_HTTP_DATA_CB(OnUrl);
DEF_HTTP_DATA_CB(OnHeaderField);
DEF_HTTP_DATA_CB(OnHeaderValue);
DEF_HTTP_CB(OnHeadersComplete);
DEF_HTTP_DATA_CB(OnBody);
private:
http_parser parser_;
http_parser_settings sets_;
HttpMessage *msg_;
CompleteCallback complete_cb_;
std::string cur_header_field_;
std::string cur_header_value_;
};
}
#endif // HTTP_PARSER_CXX_H_