-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpRequest.h
More file actions
79 lines (50 loc) · 1.21 KB
/
Copy pathHttpRequest.h
File metadata and controls
79 lines (50 loc) · 1.21 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include <ostream>
#include <string>
#include <unordered_map>
using namespace std;
enum class HttpMethod
{
GET,
POST,
PUT,
PATCH,
DELETE_,
HEAD,
OPTIONS,
CONNECT,
TRACE,
QUERY,
UNKNOWN
};
class HttpRequest
{
private:
HttpMethod method;
string path;
string version;
unordered_map<string, string> headers;
unordered_map<string, string> params;
unordered_map<string, string> query;
string clientIP;
string body;
bool parseRequestLine(const string& line);
void parseHeaders(stringstream& stream);
void parseQuery();
HttpMethod parseMethod(const string& text);
public:
HttpRequest();
bool parse(const string& rawRequest);
HttpMethod getMethod() const;
string getPath() const;
string getVersion() const;
string getHeader(const string& key) const;
string getQuery(const string& key) const;
string getBody() const;
string getParam(const string& key) const;
void setParam(const string& key,
const string& value);
void setClientIP(const string& ip);
string getClientIP() const;
};
ostream& operator<<(ostream& os, HttpMethod method);