 |
Kea
1.5.0
|
Go to the documentation of this file.
11 #include <boost/date_time/local_time/local_time.hpp>
12 #include <boost/date_time/time_facet.hpp>
15 using namespace boost::local_time;
21 const std::map<HttpStatusCode, std::string> status_code_to_description = {
22 { HttpStatusCode::OK,
"OK" },
23 { HttpStatusCode::CREATED,
"Created" },
24 { HttpStatusCode::ACCEPTED,
"Accepted" },
25 { HttpStatusCode::NO_CONTENT,
"No Content" },
26 { HttpStatusCode::MULTIPLE_CHOICES,
"Multiple Choices" },
27 { HttpStatusCode::MOVED_PERMANENTLY,
"Moved Permanently" },
28 { HttpStatusCode::MOVED_TEMPORARILY,
"Moved Temporarily" },
29 { HttpStatusCode::NOT_MODIFIED,
"Not Modified" },
30 { HttpStatusCode::BAD_REQUEST,
"Bad Request" },
31 { HttpStatusCode::UNAUTHORIZED,
"Unauthorized" },
32 { HttpStatusCode::FORBIDDEN,
"Forbidden" },
33 { HttpStatusCode::NOT_FOUND,
"Not Found" },
34 { HttpStatusCode::REQUEST_TIMEOUT,
"Request Timeout" },
35 { HttpStatusCode::INTERNAL_SERVER_ERROR,
"Internal Server Error" },
36 { HttpStatusCode::NOT_IMPLEMENTED,
"Not Implemented" },
37 { HttpStatusCode::BAD_GATEWAY,
"Bad Gateway" },
38 { HttpStatusCode::SERVICE_UNAVAILABLE,
"Service Unavailable" }
42 const std::string crlf =
"\r\n";
49 HttpResponse::HttpResponse()
59 context_->status_code_ =
static_cast<unsigned int>(status_code);
61 if (generic_body.
set_) {
64 setGenericBody(status_code);
83 for (
auto header =
context_->headers_.begin();
87 headers_[hdr->getLowerCaseName()] = hdr;
93 headers_[
"content-length"] = length_header;
104 auto header =
headers_.find(req_header->first);
107 <<
" not found in the HTTP response");
108 }
else if (!req_header->second->getValue().empty() &&
109 !header->second->isValueEqual(req_header->second->getValue())) {
113 <<
" value is " << req_header->second->getValue()
114 <<
", but " << header->second->getValue() <<
" was found");
118 }
catch (
const std::exception& ex) {
166 return ((c >= 400) && (c < 500));
173 return ((c >= 500) && (c < 600));
178 auto status_code_it = status_code_to_description.find(status_code);
179 if (status_code_it == status_code_to_description.end()) {
181 " description for the given status code "
182 <<
static_cast<uint16_t
>(status_code));
184 return (status_code_it->second);
189 return (
static_cast<uint16_t
>(status_code));
203 std::ostringstream s;
214 std::ostringstream s;
220 s << header_it->second->getName() <<
": " << header_it->second->getValue()
void checkCreated() const
Checks if the create was called.
void checkFinalized() const
Checks if the finalize was called.
std::set< HttpVersion > required_versions_
Set of required HTTP versions.
int version()
returns Kea hooks version.
std::string rfc1123Format() const
Returns time value formatted as specified in RFC 1123.
HttpResponse()
Constructor for the inbound HTTP response.
HttpStatusCode
HTTP status codes (cf RFC 2068)
virtual std::string toString() const
Returns HTTP response as string.
Encapsulates the boolean value indicating if the HttpResponse constructor should call its setGenericB...
bool set_
A storage for the boolean flag.
HttpHeaderMap headers_
Parsed HTTP headers.
static bool isServerError(const HttpStatusCode &status_code)
Checks if the status code indicates server error.
Generic exception thrown by HttpResponse class.
virtual void finalize()
Completes creation of the HTTP response.
static uint16_t statusCodeToNumber(const HttpStatusCode &status_code)
Convenience method converting status code to numeric value.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
unsigned major_
Major HTTP version.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
HttpStatusCode getStatusCode() const
Returns HTTP status code.
Base class for HttpRequest and HttpResponse.
std::string toBriefString() const
Returns HTTP version and HTTP status as a string.
bool created_
Flag indicating whether create was called.
HttpVersion http_version_
HTTP version numbers.
static std::string statusCodeToString(const HttpStatusCode &status_code)
Converts status code to string.
boost::shared_ptr< HttpHeader > HttpHeaderPtr
Pointer to the HttpHeader class.
Direction getDirection() const
Returns HTTP message direction.
HttpResponseContextPtr context_
Pointer to the HttpResponseContext holding parsed data.
HttpHeaderMap required_headers_
Map holding required HTTP headers.
bool inRequiredSet(const T &element, const std::set< T > &element_set) const
Checks if the set is empty or the specified element belongs to this set.
static bool isClientError(const HttpStatusCode &status_code)
Checks if the status code indicates client error.
virtual std::string getBody() const
Returns HTTP response body as string.
unsigned minor_
Minor HTTP version.
bool finalized_
Flag indicating whether finalize was called.
This class parses and generates time values used in HTTP.
std::string getStatusPhrase() const
Returns HTTP status phrase.
virtual std::string getDateHeaderValue() const
Returns current time formatted as required by RFC 1123.
virtual void reset()
Reset the state of the object.
virtual void create()
Commits information held in the context into the response.