Kea
1.9.9-git
|
Represents HTTP request message. More...
#include <request.h>
Public Types | |
enum | Method { Method::HTTP_GET, Method::HTTP_POST, Method::HTTP_HEAD, Method::HTTP_PUT, Method::HTTP_DELETE, Method::HTTP_OPTIONS, Method::HTTP_CONNECT, Method::HTTP_METHOD_UNKNOWN } |
HTTP methods. More... | |
Public Types inherited from isc::http::HttpMessage | |
enum | Direction { INBOUND, OUTBOUND } |
Specifies the direction of the HTTP message. More... | |
Public Member Functions | |
HttpRequest () | |
Constructor for inbound HTTP request. More... | |
HttpRequest (const Method &method, const std::string &uri, const HttpVersion &version, const HostHttpHeader &host_header=HostHttpHeader(), const BasicHttpAuthPtr &basic_auth=BasicHttpAuthPtr()) | |
Constructor for outbound HTTP request. More... | |
const HttpRequestContextPtr & | context () const |
Returns pointer to the HttpRequestContext. More... | |
virtual void | create () |
Commits information held in the context into the request. More... | |
virtual void | finalize () |
Completes creation of the HTTP request. More... | |
std::string | getBody () const |
Returns HTTP message body as string. More... | |
Method | getMethod () const |
Returns HTTP method of the request. More... | |
std::string | getUri () const |
Returns HTTP request URI. More... | |
bool | isPersistent () const |
Checks if the client has requested persistent connection. More... | |
void | requireHttpMethod (const HttpRequest::Method &method) |
Specifies an HTTP method allowed for the request. More... | |
virtual void | reset () |
Reset the state of the object. More... | |
std::string | toBriefString () const |
Returns HTTP method, URI and HTTP version as a string. More... | |
virtual std::string | toString () const |
Returns HTTP message as string. More... | |
Public Member Functions inherited from isc::http::HttpMessage | |
HttpMessage (const Direction &direction) | |
Constructor. More... | |
virtual | ~HttpMessage () |
Destructor. More... | |
Direction | getDirection () const |
Returns HTTP message direction. More... | |
HttpHeaderPtr | getHeader (const std::string &header_name) const |
Returns object encapsulating HTTP header. More... | |
std::string | getHeaderValue (const std::string &header_name) const |
Returns a value of the specified HTTP header. More... | |
uint64_t | getHeaderValueAsUint64 (const std::string &header_name) const |
Returns a value of the specified HTTP header as number. More... | |
HttpVersion | getHttpVersion () const |
Returns HTTP version number (major and minor). More... | |
bool | isFinalized () const |
Checks if the message has been successfully finalized. More... | |
void | requireHeader (const std::string &header_name) |
Specifies a required HTTP header for the HTTP message. More... | |
void | requireHeaderValue (const std::string &header_name, const std::string &header_value) |
Specifies a required value of a header in the message. More... | |
void | requireHttpVersion (const HttpVersion &version) |
Specifies HTTP version allowed. More... | |
bool | requiresBody () const |
Checks if the body is required for the HTTP message. More... | |
void | setDirection (const Direction &direction) |
Sets direction for the HTTP message. More... | |
Public Member Functions inherited from isc::hooks::CalloutHandleAssociate | |
CalloutHandleAssociate () | |
Constructor. More... | |
CalloutHandlePtr | getCalloutHandle () |
Returns callout handle. More... | |
Protected Member Functions | |
Method | methodFromString (std::string method) const |
Converts HTTP method specified in textual format to Method. More... | |
std::string | methodToString (const HttpRequest::Method &method) const |
Converts HTTP method to string. More... | |
Protected Member Functions inherited from isc::http::HttpMessage | |
void | checkCreated () const |
Checks if the create was called. More... | |
void | checkFinalized () const |
Checks if the finalize was called. More... | |
template<typename T > | |
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. More... | |
Protected Attributes | |
HttpRequestContextPtr | context_ |
Pointer to the HttpRequestContext holding parsed data. More... | |
Method | method_ |
HTTP method of the request. More... | |
std::set< Method > | required_methods_ |
Set of required HTTP methods. More... | |
Protected Attributes inherited from isc::http::HttpMessage | |
bool | created_ |
Flag indicating whether create was called. More... | |
Direction | direction_ |
Message direction (inbound or outbound). More... | |
bool | finalized_ |
Flag indicating whether finalize was called. More... | |
HttpHeaderMap | headers_ |
Parsed HTTP headers. More... | |
HttpVersion | http_version_ |
HTTP version numbers. More... | |
HttpHeaderMap | required_headers_ |
Map holding required HTTP headers. More... | |
std::set< HttpVersion > | required_versions_ |
Set of required HTTP versions. More... | |
Protected Attributes inherited from isc::hooks::CalloutHandleAssociate | |
CalloutHandlePtr | callout_handle_ |
Callout handle stored. More... | |
Additional Inherited Members | |
Protected Types inherited from isc::http::HttpMessage | |
typedef std::map< std::string, HttpHeaderPtr > | HttpHeaderMap |
Map of HTTP headers indexed by lower case header names. More... | |
Represents HTTP request message.
This derivation of the HttpMessage
class is specialized to represent HTTP requests. This class provides two constructors for creating an inbound and outbound request instance respectively. This class is associated with an instance of the HttpRequestContext
, which is used to provide request specific values, such as: HTTP method, version, URI and headers.
The derivations of this class provide specializations and specify the HTTP methods, versions and headers supported/required in the specific use cases. For example, the PostHttpRequest
class derives from HttpRequest
and it requires that request uses POST method. The PostHttpRequestJson
, which derives from PostHttpRequest
requires that the POST message includes body holding a JSON structure and provides methods to parse the JSON body.
Callouts are associated to the request.
|
strong |
isc::http::HttpRequest::HttpRequest | ( | ) |
Constructor for inbound HTTP request.
Definition at line 24 of file request.cc.
isc::http::HttpRequest::HttpRequest | ( | const Method & | method, |
const std::string & | uri, | ||
const HttpVersion & | version, | ||
const HostHttpHeader & | host_header = HostHttpHeader() , |
||
const BasicHttpAuthPtr & | basic_auth = BasicHttpAuthPtr() |
||
) |
Constructor for outbound HTTP request.
The constructor always includes Host header in the request, regardless of the HTTP version used.
method | HTTP method, e.g. POST. |
uri | URI. |
version | HTTP version. |
host_header | Host header to be included in the request. The default is the empty Host header. |
basic_auth | Basic HTTP authentication credential. The default is no authentication. |
Definition at line 30 of file request.cc.
References context(), isc::http::HttpHeader::getName(), isc::http::HttpHeader::getValue(), isc::http::HttpVersion::major_, methodToString(), and isc::http::HttpVersion::minor_.
|
inline |
Returns pointer to the HttpRequestContext.
The context holds intermediate data for creating a request. The request parser stores parsed raw data in the context. When parsing is finished, the data are validated and committed into the HttpRequest
.
Definition at line 90 of file request.h.
References context_.
Referenced by HttpRequest(), and isc::http::PostHttpRequestJson::PostHttpRequestJson().
|
virtual |
Commits information held in the context into the request.
This function reads HTTP method, version and headers from the context and validates their values. For the outbound messages, it automatically appends Content-Length header to the request, based on the length of the request body.
HttpRequestError | if the parsed request doesn't meet the specified requirements for it. |
Implements isc::http::HttpMessage.
Definition at line 58 of file request.cc.
References context_, isc::http::HttpMessage::created_, isc::http::HttpMessage::getDirection(), isc::http::HttpMessage::headers_, isc::http::HttpMessage::http_version_, isc::http::HttpMessage::inRequiredSet(), isc_throw, isc::http::HttpVersion::major_, method_, methodFromString(), methodToString(), isc::http::HttpVersion::minor_, isc::http::HttpMessage::OUTBOUND, isc::http::HttpMessage::required_headers_, required_methods_, isc::http::HttpMessage::required_versions_, reset(), and isc::Exception::what().
Referenced by isc::http::PostHttpRequestJson::finalize(), and finalize().
|
virtual |
Completes creation of the HTTP request.
This method marks the message as finalized. The outbound request may now be sent over the TCP socket. The information from the inbound message may be read, including the request body.
Implements isc::http::HttpMessage.
Reimplemented in isc::http::PostHttpRequestJson.
Definition at line 126 of file request.cc.
References create(), isc::http::HttpMessage::created_, and isc::http::HttpMessage::finalized_.
|
virtual |
Returns HTTP message body as string.
Implements isc::http::HttpMessage.
Definition at line 157 of file request.cc.
References isc::http::HttpMessage::checkFinalized(), and context_.
Referenced by toString().
HttpRequest::Method isc::http::HttpRequest::getMethod | ( | ) | const |
Returns HTTP method of the request.
Definition at line 145 of file request.cc.
References isc::http::HttpMessage::checkCreated(), and method_.
Referenced by toBriefString().
std::string isc::http::HttpRequest::getUri | ( | ) | const |
Returns HTTP request URI.
Definition at line 151 of file request.cc.
References isc::http::HttpMessage::checkCreated(), and context_.
Referenced by toBriefString().
bool isc::http::HttpRequest::isPersistent | ( | ) | const |
Checks if the client has requested persistent connection.
For the HTTP/1.0 case, the connection is persistent if the client has included Connection: keep-alive header. For the HTTP/1.1 case, the connection is assumed to be persistent unless Connection: close header has been included.
Definition at line 209 of file request.cc.
References isc::http::HttpMessage::getHeader(), isc::http::HttpMessage::getHttpVersion(), and isc::http::HttpVersion::HTTP_10().
|
protected |
Converts HTTP method specified in textual format to Method.
method | HTTP method specified in the textual format. This value is case insensitive. |
HttpRequestError | if unknown method specified. |
Definition at line 231 of file request.cc.
References HTTP_CONNECT, HTTP_DELETE, HTTP_GET, HTTP_HEAD, HTTP_OPTIONS, HTTP_POST, HTTP_PUT, and isc_throw.
Referenced by create().
|
protected |
Converts HTTP method to string.
method | HTTP method specified as enum. |
Definition at line 253 of file request.cc.
References HTTP_CONNECT, HTTP_DELETE, HTTP_GET, HTTP_HEAD, HTTP_OPTIONS, HTTP_POST, and HTTP_PUT.
Referenced by create(), HttpRequest(), and toBriefString().
void isc::http::HttpRequest::requireHttpMethod | ( | const HttpRequest::Method & | method | ) |
Specifies an HTTP method allowed for the request.
Allowed methods must be specified prior to calling create method. If no method is specified, all methods are supported.
method | HTTP method allowed for the request. |
Definition at line 53 of file request.cc.
References required_methods_.
Referenced by isc::http::PostHttpRequest::PostHttpRequest().
|
virtual |
Reset the state of the object.
Implements isc::http::HttpMessage.
Reimplemented in isc::http::PostHttpRequestJson.
Definition at line 137 of file request.cc.
References isc::http::HttpMessage::created_, isc::http::HttpMessage::finalized_, isc::http::HttpMessage::headers_, HTTP_METHOD_UNKNOWN, and method_.
Referenced by create(), and isc::http::PostHttpRequestJson::reset().
std::string isc::http::HttpRequest::toBriefString | ( | ) | const |
Returns HTTP method, URI and HTTP version as a string.
Definition at line 163 of file request.cc.
References isc::http::HttpMessage::checkFinalized(), isc::http::HttpMessage::getHttpVersion(), getMethod(), getUri(), isc::http::HttpVersion::major_, methodToString(), and isc::http::HttpVersion::minor_.
Referenced by toString().
|
virtual |
Returns HTTP message as string.
This method is called to generate the outbound HTTP message. Make sure to call finalize
prior to calling this method.
Implements isc::http::HttpMessage.
Definition at line 173 of file request.cc.
References isc::http::HttpMessage::checkFinalized(), getBody(), isc::http::HttpMessage::getHeader(), isc::http::HttpMessage::headers_, and toBriefString().
|
protected |
Pointer to the HttpRequestContext holding parsed data.
Definition at line 181 of file request.h.
Referenced by context(), create(), getBody(), getUri(), isc::http::PostHttpRequestJson::parseBodyAsJson(), and isc::http::PostHttpRequestJson::setBodyAsJson().
|
protected |
HTTP method of the request.
Definition at line 177 of file request.h.
Referenced by create(), getMethod(), and reset().
|
protected |
Set of required HTTP methods.
If the set is empty, all methods are allowed.
Definition at line 174 of file request.h.
Referenced by create(), and requireHttpMethod().