2 Star 30 Fork 7

Agedcat/WebServer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
HTTPresponse.h 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
i猫的少年 提交于 2021-06-03 23:31 . first finish
// 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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/agedcat/WebServer.git
git@gitee.com:agedcat/WebServer.git
agedcat
WebServer
WebServer
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385