-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHttpResponse.h
62 lines (49 loc) · 1.37 KB
/
HttpResponse.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
//
// Created by Administrator on 2019/9/23 0023.
//
#ifndef WEBSOCKET_HTTPRESPONSE_H
#define WEBSOCKET_HTTPRESPONSE_H
#include "public.h"
#include "EventCallback.h"
#include "Event.h"
class HttpResponse : public EventCallback {
private:
string internal_buffer;
bool status_line_send;
bool protocol_added;
bool status_code_added;
bool description_added;
string http_protocol_version;
unordered_map<string, string> headers;
Socket_t sock;
bool close_after_write_finished;
void InitStatus() {
status_line_send = false;
protocol_added = false;
status_code_added = false;
description_added = false;
headers.clear();
close_after_write_finished = false;
}
public:
explicit HttpResponse(Socket_t socket) {
sock = socket;
InitStatus();
}
HttpResponse() {
InitStatus();
}
void AddHeader(string name, string value, bool is_last);
void AddStatusLine(string protocol, int code, string description, bool is_last = false);
bool Handle(bool socket_should_close, void *event_loop) override;
void BindSocket(Socket_t socket) {
sock = socket;
}
void CloseSocketAfterWriteFinished() {
close_after_write_finished = true;
}
void HeaderSendFinished() {
internal_buffer.append("\r\n");
}
};
#endif //WEBSOCKET_HTTPRESPONSE_H