| Kea 3.0.2-git

http_header.cc
Go to the documentation of this file.
1// Copyright (C) 2017-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#include <config.h>
8
9#include <exceptions/exceptions.h>
10#include <http/http_header.h>
11#include <util/str.h>
12#include <boost/lexical_cast.hpp>
13
14 namespace isc {
15 namespace http {
16
17 HttpHeader::HttpHeader(const std::string& header_name,
18 const std::string& header_value)
19 : header_name_(header_name), header_value_(header_value) {
20}
21
22uint64_t
23 HttpHeader::getUint64Value() const {
24 try {
25 return (boost::lexical_cast<uint64_t>(header_value_));
26
27 } catch (const boost::bad_lexical_cast& ex) {
28 isc_throw(BadValue, header_name_ << " HTTP header value "
29 << header_value_ << " is not a valid number");
30 }
31}
32
33std::string
34 HttpHeader::getLowerCaseName() const {
35 std::string ln = header_name_;
36 util::str::lowercase(ln);
37 return (ln);
38}
39
40std::string
41 HttpHeader::getLowerCaseValue() const {
42 std::string lc = header_value_;
43 util::str::lowercase(lc);
44 return (lc);
45}
46
47 bool
48 HttpHeader::isValueEqual(const std::string& v) const {
49 std::string lcv = v;
50 util::str::lowercase(lcv);
51 return (lcv == getLowerCaseValue());
52}
53
54
55} // end of namespace isc::http
56} // end of namespace isc
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition exceptions/exceptions.h:132
isc::http::HttpHeader::HttpHeader
HttpHeader(const std::string &header_name, const std::string &header_value="")
Constructor.
Definition http_header.cc:17
isc::http::HttpHeader::getUint64Value
uint64_t getUint64Value() const
Returns header value as unsigned integer.
Definition http_header.cc:23
isc::http::HttpHeader::getLowerCaseName
std::string getLowerCaseName() const
Returns lower case header name.
Definition http_header.cc:34
isc::http::HttpHeader::getLowerCaseValue
std::string getLowerCaseValue() const
Returns lower case header value.
Definition http_header.cc:41
isc::http::HttpHeader::isValueEqual
bool isValueEqual(const std::string &v) const
Case insensitive comparison of header value.
Definition http_header.cc:48
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
http_header.h
isc::http
Definition auth_config.h:19
isc::util::str::lowercase
void lowercase(string &text)
Convert string to lowercase.
Definition str.cc:134
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
str.h