header.h
Go to the documentation of this file.
/*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Thomas Voß <thomas.voss@canonical.com>
*/
#ifndef CORE_NET_HTTP_HEADER_H_
#define CORE_NET_HTTP_HEADER_H_
#include <core/net/visibility.h>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <functional>
namespace core
{
namespace net
{
namespace http
{
class CORE_NET_DLL_PUBLIC Header
{
public:
static std::string canonicalize_key(const std::string& key);
virtual ~Header() = default;
virtual bool has(const std::string& key, const std::string& value) const;
virtual bool has(const std::string& key) const;
virtual void add(const std::string& key, const std::string& value);
virtual void remove(const std::string& key);
virtual void remove(const std::string& key, const std::string& value);
virtual void set(const std::string& key, const std::string& value);
virtual void enumerate(const std::function<void(const std::string&, const std::set<std::string>&)>& enumerator) const;
private:
std::map<std::string, std::set<std::string>> fields;
};
}
}
}
#endif // CORE_NET_HTTP_HEADER_H_
core::net::http::Header
The Header class encapsulates the headers of an HTTP request/response.
Definition header.h:39
core::net::http::Header::enumerate
virtual void enumerate(const std::function< void(const std::string &, const std::set< std::string > &)> &enumerator) const
enumerate iterates over the known fields and invokes the given enumerator for each of them.
core::net::http::Header::has
virtual bool has(const std::string &key) const
has checks if the header contains any entry for the given key.
core::net::http::Header::add
virtual void add(const std::string &key, const std::string &value)
add adds the given value for the given key to the header.
core::net::http::Header::has
virtual bool has(const std::string &key, const std::string &value) const
has checks if the header contains an entry for the given key with the given value.
core::net::http::Header::remove
virtual void remove(const std::string &key, const std::string &value)
remove erases the given value for the given key from the header.
core::net::http::Header::~Header
virtual ~Header()=default
core::net::http::Header::set
virtual void set(const std::string &key, const std::string &value)
set assigns the given value to the entry with key 'key' and replaces any previous value.
core::net::http::Header::canonicalize_key
static std::string canonicalize_key(const std::string &key)
canonicalize_key returns the canonical form of the header key 'key'.
core::net::http::Header::remove
virtual void remove(const std::string &key)
remove erases all values for the given key from the header.
core::net::http
Definition client.h:39
core::net
Definition error.h:28
core
Definition location.h:24
visibility.h
CORE_NET_DLL_PUBLIC
#define CORE_NET_DLL_PUBLIC
Definition visibility.h:25