-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHttpProtocolParser.h
67 lines (53 loc) · 1.6 KB
/
HttpProtocolParser.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
65
66
67
//
// Created by Administrator on 2019/9/23 0023.
//
#ifndef WEBSOCKET_HTTPPROTOCOLPARSER_H
#define WEBSOCKET_HTTPPROTOCOLPARSER_H
#include "public.h"
#include "SystemCallException.h"
#include "Event.h"
class HttpProtocolParser {
protected:
bool is_parse_finished;//whether http request header has been parse finished
bool is_request_line_parse_finished;//whether http request line has been parse finished
protected:
unordered_map<string, string> headers;//http headers
int socket;//bind socket
string internal_buffer;//internal buffer for receive content from client
string method;//request method
string uri;//request uri
string http_version;//request http version
int next_search_pos;
bool socket_closed;
EventLoop *event_loop;
void InitStatus() {
is_parse_finished = false;
is_request_line_parse_finished = false;
socket = 0;
headers.clear();//clear parsed headers
internal_buffer.clear();//clear internal buffer
next_search_pos = 0;
socket_closed = false;
}
void ParseRequestLine(int pos);
virtual void ProcessHttpHeader(string &name, string &value) = 0;
size_t ReadFromSocket();
void PrintHeaders();
public:
HttpProtocolParser() {
InitStatus();
}
explicit HttpProtocolParser(int socket) {
InitStatus();
this->socket = socket;
}
void SetSocket(int fd) {
socket = fd;
InitStatus();
}
void Parse();
void BindEventSystem(EventLoop *eventLoop) {
event_loop = eventLoop;
}
};
#endif //WEBSOCKET_HTTPPROTOCOLPARSER_H