-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHttp_conn.h
48 lines (42 loc) · 1.03 KB
/
Http_conn.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
#pragma once
#include <string>
#include <unordered_map>
#include <iostream>
//#include <sys/mman.h>
#include <memory>
#include <functional>
using namespace std;
enum METHOD{METHOD_GET,METHOD_POST};
enum HTTPVERSION{HTTP_10,HTTP_11};
enum PARSESTATE{PARSE_ERROR,PARSE_METHOD,PARSE_HEADER,PARSE_SUCCESS};
class Channel;
typedef shared_ptr<Channel> SP_Channel;
class Http_conn{
public:
Http_conn(SP_Channel channel);
~Http_conn();
private:
typedef function<PARSESTATE()> CallBack;
CallBack handleparse[4];
SP_Channel channel;
bool keepalive;
int pos;
int size;
string inbuffer;
string storage;
string path;
string filetype;
METHOD method;
HTTPVERSION version;
PARSESTATE parsestate;
unordered_map<string, string> header;
PARSESTATE parseMethod();
PARSESTATE parseHeader();
PARSESTATE parseError();
PARSESTATE parseSuccess();
void parse();
void send();
bool Read(string& msg, string str);
void initmsg();
void handleError(int errornum, string msg);
};