http_header::add_entry: add param replace for checking if replade the old exist value

This commit is contained in:
zsx 2017-12-28 17:53:34 +08:00
parent 05b485b6c4
commit 612bced38d
2 changed files with 13 additions and 7 deletions

View File

@ -70,9 +70,11 @@ public:
* HTTP * HTTP
* @param name {const char*} * @param name {const char*}
* @param value {const char*} * @param value {const char*}
* @param replace {bool}
* @return {http_header&} 便 * @return {http_header&} 便
*/ */
http_header& add_entry(const char* name, const char* value); http_header& add_entry(const char* name, const char* value,
bool replace = true);
/** /**
* HTTP Content-Length * HTTP Content-Length

View File

@ -122,11 +122,14 @@ http_header& http_header::set_request_mode(bool onoff)
return *this; return *this;
} }
http_header& http_header::add_entry(const char* name, const char* value) http_header& http_header::add_entry(const char* name, const char* value,
bool replace /* = true */)
{ {
if (name == NULL || *name == 0 || value == NULL || *value == 0) if (name == NULL || *name == 0 || value == NULL || *value == 0)
return *this; return *this;
if (replace)
{
std::list<HTTP_HDR_ENTRY*>::iterator it = entries_.begin(); std::list<HTTP_HDR_ENTRY*>::iterator it = entries_.begin();
for (; it != entries_.end(); ++it) for (; it != entries_.end(); ++it)
{ {
@ -136,6 +139,7 @@ http_header& http_header::add_entry(const char* name, const char* value)
return *this; return *this;
} }
} }
}
HTTP_HDR_ENTRY* entry = (HTTP_HDR_ENTRY*) HTTP_HDR_ENTRY* entry = (HTTP_HDR_ENTRY*)
dbuf_->dbuf_calloc(sizeof(HTTP_HDR_ENTRY)); dbuf_->dbuf_calloc(sizeof(HTTP_HDR_ENTRY));