Kea  2.1.7-git
http_header.cc
Go to the documentation of this file.
1 // Copyright (C) 2017-2018 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 
10 #include <http/http_header.h>
11 #include <util/strutil.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 
22 uint64_t
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 
33 std::string
35  std::string ln = header_name_;
37  return (ln);
38 }
39 
40 std::string
42  std::string lc = header_value_;
44  return (lc);
45 }
46 
47 bool
48 HttpHeader::isValueEqual(const std::string& v) const {
49  std::string lcv = v;
51  return (lcv == getLowerCaseValue());
52 }
53 
54 
55 } // end of namespace isc::http
56 } // end of namespace isc
void lowercase(std::string &text)
Lowercase String.
Definition: strutil.h:151
HttpHeader(const std::string &header_name, const std::string &header_value="")
Constructor.
Definition: http_header.cc:17
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
std::string getLowerCaseName() const
Returns lower case header name.
Definition: http_header.cc:34
bool isValueEqual(const std::string &v) const
Case insensitive comparison of header value.
Definition: http_header.cc:48
Defines the logger used by the top-level component of kea-lfc.
uint64_t getUint64Value() const
Returns header value as unsigned integer.
Definition: http_header.cc:23
std::string getLowerCaseValue() const
Returns lower case header value.
Definition: http_header.cc:41