http请求报文如下:

http响应报文如下:

请求报文解析

响应报文解析

- 基础结构类:Response和Request,其中都包含一个Url类,用于解析得到路径和Query参数。
- 工具类:HttpParserr,HttpParser用于解析纯http报文然后得到对应的Response或Request,如果要将Request或Response组合成对应的http报文直接调用它们的to_string()方法即可。

代码结构:

void simple(){
http::Parser parser;
auto req = parser.ToRequest(buffer);
std::cout << req.to_string(); //根据request内容获取对应的http报文
req.m_head()["dfasf"] = "fda"; //随意设置request的header
req.body() = "fdsafsadf"; //设置request的body部分
//request的特殊字段(GET的FORM和POST的form
auto v = req.Query("test"); //获取第一个值
auto v1 = req.PostQuery("test"); //获取post表单里的第一个query值
req.PostMultiPart("test"); //返回form-data的键值(可以传入文件
http::Response response;
response.SetStatus(http::OK);
response.SetContentType(http::ACCEPT_CONTENT_TYPE::T_JSON);
response.SetConnection(false);
response.body() = R"({"hello world!":2323})";
}