forked from skyfireitdiy/sflib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsf_http_header.h
93 lines (76 loc) · 2.22 KB
/
sf_http_header.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* @version 1.0.0
* @author skyfire
* @mail [email protected]
* @see http://github.com/skyfireitdiy/sflib
* @file sf_http_header.h
* sflib第一版本发布
* 版本号1.0.0
* 发布日期:2018-10-22
*/
#pragma once
#include <string>
#include <map>
#include <vector>
#include "sf_http_utils.h"
namespace skyfire
{
class sf_http_base_server;
/**
* @brief http头
*/
class sf_http_header{
sf_http_header_t header_data__;
std::vector<std::string> cookie_str_vec__;
public:
/**
* 清空http头
*/
void clear();
/**
* 设置头,注意:不支持同名http头,设置同名http头会将前一个同名http头覆盖
* @param key 键
* @param value 值
*/
void set_header(std::string key, const std::string& value);
/**
* 获取头数据
* @param key 键
* @param default_value 默认值(如果没有找到指定的http头,则会返回该值)
* @return 值
*/
std::string get_header_value(std::string key, const std::string& default_value = "") const;
/**
* 删除指定的头
* @param key 键
*/
void remove_header(std::string key);
/**
* 获取头的列表
* @return 头的键集合
*/
std::vector<std::string> get_key_list() const;
/**
* 获取头的原始类型
* @return sf_http_header_t类型的头数据
*/
sf_http_header_t get_header() const;
/**
* 设置原始的头数据
* @param header sf_http_header_t类型的头数据
*/
void set_header(const sf_http_header_t& header);
/**
* 判断是否有指定的http头
* @param key 键
* @return 是否存在
*/
bool has_key(const std::string& key) const ;
/**
* 生成符合http标准的字符串格式的头文本,用于发送/查看,注意:cookie不包含在头列表中,但是生成字符串时,会将cookie编入
* @return 生成的头文本
*/
std::string to_string() const;
friend sf_http_base_server;
};
}