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,18 +122,22 @@ 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;
std::list<HTTP_HDR_ENTRY*>::iterator it = entries_.begin(); if (replace)
for (; it != entries_.end(); ++it)
{ {
if (strcasecmp((*it)->name, name) == 0) std::list<HTTP_HDR_ENTRY*>::iterator it = entries_.begin();
for (; it != entries_.end(); ++it)
{ {
(*it)->value = dbuf_->dbuf_strdup(value); if (strcasecmp((*it)->name, name) == 0)
return *this; {
(*it)->value = dbuf_->dbuf_strdup(value);
return *this;
}
} }
} }