net-cpp ..
C++11 library for networking purposes
header.h
Go to the documentation of this file.
1/*
2 * Copyright © 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17 */
18#ifndef CORE_NET_HTTP_HEADER_H_
19#define CORE_NET_HTTP_HEADER_H_
20
21#include <core/net/visibility.h>
22
23#include <map>
24#include <memory>
25#include <set>
26#include <string>
27#include <functional>
28
29namespace core
30{
31namespace net
32{
33namespace http
34{
39{
40public:
51 static std::string canonicalize_key(const std::string& key);
52
53 virtual ~Header() = default;
54
60 virtual bool has(const std::string& key, const std::string& value) const;
61
66 virtual bool has(const std::string& key) const;
67
71 virtual void add(const std::string& key, const std::string& value);
72
76 virtual void remove(const std::string& key);
77
81 virtual void remove(const std::string& key, const std::string& value);
82
86 virtual void set(const std::string& key, const std::string& value);
87
91 virtual void enumerate(const std::function<void(const std::string&, const std::set<std::string>&)>& enumerator) const;
92
93private:
95 std::map<std::string, std::set<std::string>> fields;
97};
98}
99}
100}
101
102#endif // CORE_NET_HTTP_HEADER_H_
The Header class encapsulates the headers of an HTTP request/response.
Definition: header.h:39
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.
virtual bool has(const std::string &key) const
has checks if the header contains any entry for the given key.
virtual void add(const std::string &key, const std::string &value)
add adds the given value for the given key to the header.
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.
virtual void remove(const std::string &key, const std::string &value)
remove erases the given value for the given key from the header.
virtual ~Header()=default
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.
static std::string canonicalize_key(const std::string &key)
canonicalize_key returns the canonical form of the header key 'key'.
virtual void remove(const std::string &key)
remove erases all values for the given key from the header.
Definition: location.h:24
#define CORE_NET_DLL_PUBLIC
Definition: visibility.h:25