mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 08:14:15 +00:00
* HTTP.{cpp,h} : add HTTPMsg::{add,del}_header() helpers
This commit is contained in:
parent
50ff0d251a
commit
a461f462d2
15
HTTP.cpp
15
HTTP.cpp
@ -184,6 +184,21 @@ namespace http {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HTTPMsg::add_header(const char *name, const char *value, bool replace) {
|
||||||
|
std::size_t count = headers.count(name);
|
||||||
|
if (count && !replace)
|
||||||
|
return;
|
||||||
|
if (count) {
|
||||||
|
headers[name] = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
headers.insert(std::pair<std::string, std::string>(name, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTTPMsg::del_header(const char *name) {
|
||||||
|
headers.erase(name);
|
||||||
|
}
|
||||||
|
|
||||||
int HTTPReq::parse(const char *buf, size_t len) {
|
int HTTPReq::parse(const char *buf, size_t len) {
|
||||||
std::string str(buf, len);
|
std::string str(buf, len);
|
||||||
return parse(str);
|
return parse(str);
|
||||||
|
3
HTTP.h
3
HTTP.h
@ -56,6 +56,9 @@ namespace http {
|
|||||||
|
|
||||||
struct HTTPMsg {
|
struct HTTPMsg {
|
||||||
std::map<std::string, std::string> headers;
|
std::map<std::string, std::string> headers;
|
||||||
|
|
||||||
|
void add_header(const char *name, const char *value, bool replace = false);
|
||||||
|
void del_header(const char *name);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HTTPReq : HTTPMsg {
|
struct HTTPReq : HTTPMsg {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user