Kea 2.7.5
|
Represents HTTP request message. More...
#include <request.h>
Public Types | |
enum class | Method { HTTP_GET , HTTP_POST , HTTP_HEAD , HTTP_PUT , HTTP_DELETE , HTTP_OPTIONS , HTTP_CONNECT , 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. | |
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. | |
const HttpRequestContextPtr & | context () const |
Returns pointer to the HttpRequestContext. | |
virtual void | create () |
Commits information held in the context into the request. | |
virtual void | finalize () |
Completes creation of the HTTP request. | |
std::string | getBasicAuth () const |
Returns recorded basic auth. | |
std::string | getBody () const |
Returns HTTP message body as string. | |
std::string | getCustom () const |
Returns recorded custom name. | |
std::string | getIssuer () const |
Returns recorded issuer name. | |
Method | getMethod () const |
Returns HTTP method of the request. | |
std::string | getRemote () const |
Returns remote address. | |
std::string | getSubject () const |
Returns recorded subject name. | |
bool | getTls () const |
Access control parameters: get/set methods. | |
std::string | getUri () const |
Returns HTTP request URI. | |
bool | isPersistent () const |
Checks if the client has requested persistent connection. | |
void | requireHttpMethod (const HttpRequest::Method &method) |
Specifies an HTTP method allowed for the request. | |
virtual void | reset () |
Reset the state of the object. | |
void | setBasicAuth (const std::string &basic_auth) |
Set (record) basic auth. | |
void | setCustom (const std::string &custom) |
Set (record) custom name. | |
void | setIssuer (const std::string &issuer) |
Set (record) issuer name. | |
void | setRemote (const std::string &remote) |
Set remote address. | |
void | setSubject (const std::string &subject) |
Set (record) subject name. | |
void | setTls (bool tls) |
Set (record) TLS usage. | |
std::string | toBriefString () const |
Returns HTTP method, URI and HTTP version as a string. | |
virtual std::string | toString () const |
Returns HTTP message as string. | |
Public Member Functions inherited from isc::http::HttpMessage | |
HttpMessage (const Direction &direction) | |
Constructor. | |
virtual | ~HttpMessage () |
Destructor. | |
Direction | getDirection () const |
Returns HTTP message direction. | |
HttpHeaderPtr | getHeader (const std::string &header_name) const |
Returns object encapsulating HTTP header. | |
std::string | getHeaderValue (const std::string &header_name) const |
Returns a value of the specified HTTP header. | |
uint64_t | getHeaderValueAsUint64 (const std::string &header_name) const |
Returns a value of the specified HTTP header as number. | |
HttpVersion | getHttpVersion () const |
Returns HTTP version number (major and minor). | |
bool | isFinalized () const |
Checks if the message has been successfully finalized. | |
void | requireHeader (const std::string &header_name) |
Specifies a required HTTP header for the HTTP message. | |
void | requireHeaderValue (const std::string &header_name, const std::string &header_value) |
Specifies a required value of a header in the message. | |
void | requireHttpVersion (const HttpVersion &version) |
Specifies HTTP version allowed. | |
bool | requiresBody () const |
Checks if the body is required for the HTTP message. | |
void | setDirection (const Direction &direction) |
Sets direction for the HTTP message. | |
Public Member Functions inherited from isc::hooks::CalloutHandleAssociate | |
CalloutHandleAssociate () | |
Constructor. | |
CalloutHandlePtr | getCalloutHandle () |
Returns callout handle. | |
void | resetCalloutHandle () |
Reset callout handle. | |
Static Public Attributes | |
static bool | recordBasicAuth_ = false |
Record basic auth. | |
static bool | recordIssuer_ = false |
Record issuer name. | |
static bool | recordSubject_ = false |
Access control parameters: Flags which indicate what information to record. | |
Protected Member Functions | |
Method | methodFromString (std::string method) const |
Converts HTTP method specified in textual format to Method. | |
std::string | methodToString (const HttpRequest::Method &method) const |
Converts HTTP method to string. | |
Protected Member Functions inherited from isc::http::HttpMessage | |
void | checkCreated () const |
Checks if the create was called. | |
void | checkFinalized () const |
Checks if the finalize was called. | |
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. | |
Protected Attributes | |
std::string | basic_auth_ |
Basic auth. | |
HttpRequestContextPtr | context_ |
Pointer to the HttpRequestContext holding parsed data. | |
std::string | custom_ |
Custom name. | |
std::string | issuer_ |
Issuer name. | |
Method | method_ |
HTTP method of the request. | |
std::string | remote_ |
Remote address. | |
std::set< Method > | required_methods_ |
Set of required HTTP methods. | |
std::string | subject_ |
Subject name. | |
bool | tls_ |
TLS usage. | |
Protected Attributes inherited from isc::http::HttpMessage | |
bool | created_ |
Flag indicating whether create was called. | |
Direction | direction_ |
Message direction (inbound or outbound). | |
bool | finalized_ |
Flag indicating whether finalize was called. | |
HttpHeaderMap | headers_ |
Parsed HTTP headers. | |
HttpVersion | http_version_ |
HTTP version numbers. | |
HttpHeaderMap | required_headers_ |
Map holding required HTTP headers. | |
std::set< HttpVersion > | required_versions_ |
Set of required HTTP versions. | |
Protected Attributes inherited from isc::hooks::CalloutHandleAssociate | |
CalloutHandlePtr | callout_handle_ |
Callout handle stored. | |
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. | |
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.
Objects of this class is used to record some parameters for access control:
Callouts are associated to the request.
|
strong |
isc::http::HttpRequest::HttpRequest | ( | ) |
Constructor for inbound HTTP request.
Definition at line 30 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 38 of file request.cc.
References context(), methodToString(), and version().
|
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 98 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 68 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 132 of file request.cc.
References create(), isc::http::HttpMessage::created_, and isc::http::HttpMessage::finalized_.
|
inline |
Returns recorded basic auth.
Definition at line 223 of file request.h.
References basic_auth_.
|
virtual |
Returns HTTP message body as string.
Implements isc::http::HttpMessage.
Definition at line 163 of file request.cc.
References isc::http::HttpMessage::checkFinalized(), and context_.
Referenced by toString().
|
inline |
|
inline |
HttpRequest::Method isc::http::HttpRequest::getMethod | ( | ) | const |
Returns HTTP method of the request.
Definition at line 151 of file request.cc.
References isc::http::HttpMessage::checkCreated(), and method_.
Referenced by toBriefString().
|
inline |
|
inline |
|
inline |
std::string isc::http::HttpRequest::getUri | ( | ) | const |
Returns HTTP request URI.
Definition at line 157 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 214 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 236 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 258 of file request.cc.
References HTTP_CONNECT, HTTP_DELETE, HTTP_GET, HTTP_HEAD, HTTP_OPTIONS, HTTP_POST, and HTTP_PUT.
Referenced by HttpRequest(), create(), 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 63 of file request.cc.
References required_methods_.
Referenced by isc::http::PostHttpRequest::PostHttpRequest(), and isc::http::PostHttpRequest::PostHttpRequest().
|
virtual |
Reset the state of the object.
Implements isc::http::HttpMessage.
Reimplemented in isc::http::PostHttpRequestJson.
Definition at line 143 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().
|
inline |
Set (record) basic auth.
basic_auth | the basic auth. |
Definition at line 230 of file request.h.
References basic_auth_.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
std::string isc::http::HttpRequest::toBriefString | ( | ) | const |
Returns HTTP method, URI and HTTP version as a string.
Definition at line 169 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 179 of file request.cc.
References isc::http::HttpMessage::checkFinalized(), getBody(), isc::http::HttpMessage::getHeader(), isc::http::HttpMessage::headers_, and toBriefString().
|
protected |
Basic auth.
Definition at line 303 of file request.h.
Referenced by getBasicAuth(), and setBasicAuth().
|
protected |
Pointer to the HttpRequestContext holding parsed data.
Definition at line 288 of file request.h.
Referenced by context(), create(), getBody(), getUri(), isc::http::PostHttpRequestJson::parseBodyAsJson(), and isc::http::PostHttpRequestJson::setBodyAsJson().
|
protected |
|
protected |
|
protected |
HTTP method of the request.
Definition at line 284 of file request.h.
Referenced by create(), getMethod(), and reset().
|
static |
Record basic auth.
Definition at line 258 of file request.h.
Referenced by isc::http::BasicHttpAuthConfig::checkAuth().
|
static |
Record issuer name.
Definition at line 255 of file request.h.
Referenced by isc::http::HttpConnection::recordParameters().
|
static |
Access control parameters: Flags which indicate what information to record.
Remote address and TLS usage are always recorded.
Record subject name.
Definition at line 252 of file request.h.
Referenced by isc::http::HttpConnection::recordParameters().
|
protected |
Remote address.
Definition at line 291 of file request.h.
Referenced by getRemote(), isc::http::PostHttpRequestJson::parseBodyAsJson(), and setRemote().
|
protected |
Set of required HTTP methods.
If the set is empty, all methods are allowed.
Definition at line 281 of file request.h.
Referenced by create(), and requireHttpMethod().
|
protected |
Subject name.
Definition at line 297 of file request.h.
Referenced by getSubject(), and setSubject().
|
protected |