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 9 #include <exceptions/exceptions.h> 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 HttpHeader(const std::string & header_name,const std::string & header_value)17HttpHeader::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 getUint64Value() const23HttpHeader::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 33 std::string getLowerCaseName() const34HttpHeader::getLowerCaseName() const { 35 std::string ln = header_name_; 36 util::str::lowercase(ln); 37 return (ln); 38 } 39 40 std::string getLowerCaseValue() const41HttpHeader::getLowerCaseValue() const { 42 std::string lc = header_value_; 43 util::str::lowercase(lc); 44 return (lc); 45 } 46 47 bool isValueEqual(const std::string & v) const48HttpHeader::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 57