-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpRequest.h
More file actions
66 lines (48 loc) · 1.28 KB
/
Copy pathHttpRequest.h
File metadata and controls
66 lines (48 loc) · 1.28 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
#ifndef HTTPSERVER_HTTPREQUEST_H
#define HTTPSERVER_HTTPREQUEST_H
#include "Buffer.h"
#include <map>
#include <string>
class HttpRequest {
public:
enum class CheckState {
kCheckRequestLine = 0,
kCheckRequestHead,
kCheckRequestBody,
kFinished
};
enum class Method {
kGet = 0,
kPost
};
enum class Version {
kHttp10 = 0,
kHttp11
};
enum class HttpCode {
kNoRequest = 0,
kBadRequest,
kInternalError
};
HttpRequest();
void reset(HttpRequest& other);
bool parse(Buffer& buf);
bool gotAll() const;
void setMethod(const char* begin, const char* end);
void setVersion(Version v);
Version getVersion() const;
std::string getVersionString() const;
void setUrl(const char* begin, const char* end);
std::string getUrl() const;
void addHeader(const char* begin, const char* colon, const char* end);
std::string getHeader(const std::string& field) const;
void printHeaders() const; // for debug
private:
bool parseRequestLine_(const char* begin, const char* end);
CheckState checkState_;
Method method_;
Version version_;
std::string url_;
std::map<std::string, std::string> headers_;
};
#endif //