From a461f462d223d1004423aff3fce5276800fca7e0 Mon Sep 17 00:00:00 2001 From: hagen Date: Tue, 24 May 2016 00:00:00 +0000 Subject: [PATCH] * HTTP.{cpp,h} : add HTTPMsg::{add,del}_header() helpers --- HTTP.cpp | 15 +++++++++++++++ HTTP.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/HTTP.cpp b/HTTP.cpp index ef43d55f..f74e9429 100644 --- a/HTTP.cpp +++ b/HTTP.cpp @@ -184,6 +184,21 @@ namespace http { 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(name, value)); + } + + void HTTPMsg::del_header(const char *name) { + headers.erase(name); + } + int HTTPReq::parse(const char *buf, size_t len) { std::string str(buf, len); return parse(str); diff --git a/HTTP.h b/HTTP.h index 82594874..e13fe547 100644 --- a/HTTP.h +++ b/HTTP.h @@ -56,6 +56,9 @@ namespace http { struct HTTPMsg { std::map headers; + + void add_header(const char *name, const char *value, bool replace = false); + void del_header(const char *name); }; struct HTTPReq : HTTPMsg {