-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathHTTPresponse.h
59 lines (41 loc) · 1.23 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
// encode UTF-8
// @Author : Aged_cat
// @Date : 2021-05-04
#ifndef HTTP_RESPONSE_H
#define HTTP_RESPONSE_H
#include <unordered_map>
#include <fcntl.h> //open
#include <unistd.h> //close
#include <sys/stat.h> //stat
#include <sys/mman.h> //mmap,munmap
#include <assert.h>
#include "buffer.h"
class HTTPresponse
{
public:
HTTPresponse();
~HTTPresponse();
void init(const std::string& srcDir,std::string& path,bool isKeepAlive=false,int code=-1);
void makeResponse(Buffer& buffer);
void unmapFile_();
char* file();
size_t fileLen() const;
void errorContent(Buffer& buffer,std::string message);
int code() const {return code_;}
private:
void addStateLine_(Buffer& buffer);
void addResponseHeader_(Buffer& buffer);
void addResponseContent_(Buffer& buffer);
void errorHTML_();
std::string getFileType_();
int code_;
bool isKeepAlive_;
std::string path_;
std::string srcDir_;
char* mmFile_;
struct stat mmFileStat_;
static const std::unordered_map<std::string, std::string> SUFFIX_TYPE;
static const std::unordered_map<int, std::string> CODE_STATUS;
static const std::unordered_map<int, std::string> CODE_PATH;
};
#endif //HTTP_RESPONSE_H