Coverage Report

Created: 2026-05-16 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/kea/src/lib/http/cfg_http_header.h
Line
Count
Source
1
// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
2
//
3
// This Source Code Form is subject to the terms of the Mozilla Public
4
// License, v. 2.0. If a copy of the MPL was not distributed with this
5
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7
#ifndef CFG_HTTP_HEADER_H
8
#define CFG_HTTP_HEADER_H
9
10
#include <cc/cfg_to_element.h>
11
#include <cc/data.h>
12
#include <cc/user_context.h>
13
#include <http/request.h>
14
#include <http/response.h>
15
16
namespace isc {
17
namespace http {
18
19
/// @brief Config HTTP header.
20
///
21
/// Extra headers to include in a message are configured as a list of
22
/// objects of this class. At the difference of other HTTP header classes
23
/// there is no numeric value.
24
class CfgHttpHeader : public isc::data::UserContext, public isc::data::CfgToElement {
25
public:
26
    /// @brief Header name.
27
    std::string name_;
28
29
    /// @brief Header value.
30
    std::string value_;
31
32
    /// @brief Constructor.
33
    ///
34
    /// @param name Header name.
35
    /// @param value Header value.
36
    CfgHttpHeader(const std::string& name, const std::string& value)
37
0
        : name_(name), value_(value) {
38
0
    }
39
40
    /// @brief Unparses config HTTP header.
41
    ///
42
    /// @return A pointer to unparsed header configuration.
43
    virtual isc::data::ElementPtr toElement() const;
44
};
45
46
/// @brief Collection of config HTTP headers.
47
typedef std::vector<CfgHttpHeader> CfgHttpHeaders;
48
49
/// @brief Copy config HTTP headers to message.
50
///
51
/// @tparam HTTP_MSG Either HttpRequest or HttpResponse.
52
/// @param headers Config HTTP headers.
53
/// @param message HTTP_MSG target object.
54
template<typename HTTP_MSG>
55
216
void copyHttpHeaders(const CfgHttpHeaders& headers, const HTTP_MSG& message) {
56
216
    for (auto const& header : headers) {
57
0
        message.context()->headers_.
58
0
            push_back(HttpHeaderContext(header.name_, header.value_));
59
0
    }
60
216
}
void isc::http::copyHttpHeaders<isc::http::HttpResponse>(std::__1::vector<isc::http::CfgHttpHeader, std::__1::allocator<isc::http::CfgHttpHeader> > const&, isc::http::HttpResponse const&)
Line
Count
Source
55
216
void copyHttpHeaders(const CfgHttpHeaders& headers, const HTTP_MSG& message) {
56
216
    for (auto const& header : headers) {
57
0
        message.context()->headers_.
58
0
            push_back(HttpHeaderContext(header.name_, header.value_));
59
0
    }
60
216
}
Unexecuted instantiation: void isc::http::copyHttpHeaders<isc::http::HttpResponseJson>(std::__1::vector<isc::http::CfgHttpHeader, std::__1::allocator<isc::http::CfgHttpHeader> > const&, isc::http::HttpResponseJson const&)
61
62
/// @brief Unparse config HTTP headers.
63
///
64
/// @param headers Config HTTP headers.
65
/// @return A pointer to unparsed headers configuration.
66
isc::data::ElementPtr CfgHttpHeaderstoElement(const CfgHttpHeaders& headers);
67
68
/// @brief Parse config HTTP headers.
69
///
70
/// @param config Element holding the HTTP headers configuration.
71
/// @return The HTTP headers.
72
/// @throw DhcpConfigError when the configuration is invalid.
73
CfgHttpHeaders parseCfgHttpHeaders(const isc::data::ConstElementPtr& config);
74
75
} // namespace http
76
} // namespace isc
77
78
#endif