mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 02:47:56 +08:00
http_header::add_entry: add param replace for checking if replade the old exist value
This commit is contained in:
parent
05b485b6c4
commit
612bced38d
@ -70,9 +70,11 @@ public:
|
||||
* 向 HTTP 头中添加字段
|
||||
* @param name {const char*} 字段名,非空指针
|
||||
* @param value {const char*} 字段值,非空指针
|
||||
* @param replace {bool} 如果存在重复项时是否自动覆盖旧数据
|
||||
* @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 字段
|
||||
|
@ -122,18 +122,22 @@ http_header& http_header::set_request_mode(bool onoff)
|
||||
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)
|
||||
return *this;
|
||||
|
||||
std::list<HTTP_HDR_ENTRY*>::iterator it = entries_.begin();
|
||||
for (; it != entries_.end(); ++it)
|
||||
if (replace)
|
||||
{
|
||||
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);
|
||||
return *this;
|
||||
if (strcasecmp((*it)->name, name) == 0)
|
||||
{
|
||||
(*it)->value = dbuf_->dbuf_strdup(value);
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user