1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
/*
* 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
{
/**
* @brief The Header class encapsulates the headers of an HTTP request/response.
*/
class CORE_NET_DLL_PUBLIC Header
{
public:
/**
* @brief canonicalize_key returns the canonical form of the header key 'key'.
*
* The canonicalization converts the first
* letter and any letter following a hyphen to upper case;
* the rest are converted to lowercase. For example, the
* canonical key for "accept-encoding" is "Accept-Encoding".
*
* @param key The key to be canonicalized.
*/
static std::string canonicalize_key(const std::string& key);
virtual ~Header() = default;
/**
* @brief has checks if the header contains an entry for the given key with the given value.
* @param key The key into the header map.
* @param value The value to check for.
*/
virtual bool has(const std::string& key, const std::string& value) const;
/**
* @brief has checks if the header contains any entry for the given key.
* @param key The key into the header map.
*/
virtual bool has(const std::string& key) const;
/**
* @brief add adds the given value for the given key to the header.
*/
virtual void add(const std::string& key, const std::string& value);
/**
* @brief remove erases all values for the given key from the header.
*/
virtual void remove(const std::string& key);
/**
* @brief remove erases the given value for the given key from the header.
*/
virtual void remove(const std::string& key, const std::string& value);
/**
* @brief set assigns the given value to the entry with key 'key' and replaces any previous value.
*/
virtual void set(const std::string& key, const std::string& value);
/**
* @brief enumerate iterates over the known fields and invokes the given enumerator for each of them.
*/
virtual void enumerate(const std::function<void(const std::string&, const std::set<std::string>&)>& enumerator) const;
private:
/// @cond
std::map<std::string, std::set<std::string>> fields;
/// @endcond
};
}
}
}
#endif // CORE_NET_HTTP_HEADER_H_
|