Kea  2.3.5-git
isc::http::HttpRequest Class Reference

Represents HTTP request message. More...

#include <request.h>

+ Inheritance diagram for isc::http::HttpRequest:

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 HttpRequestContextPtrcontext () 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 getBasicAuth () const
 Returns recorded basic auth. More...
 
std::string getBody () const
 Returns HTTP message body as string. More...
 
std::string getCustom () const
 Returns recorded custom name. More...
 
std::string getIssuer () const
 Returns recorded issuer name. More...
 
Method getMethod () const
 Returns HTTP method of the request. More...
 
std::string getRemote () const
 Returns remote address. More...
 
std::string getSubject () const
 Returns recorded subject name. More...
 
bool getTls () const
 Access control parameters: get/set methods. 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...
 
void setBasicAuth (const std::string &basic_auth)
 Set (record) basic auth. More...
 
void setCustom (const std::string &custom)
 Set (record) custom name. More...
 
void setIssuer (const std::string &issuer)
 Set (record) issuer name. More...
 
void setRemote (const std::string &remote)
 Set remote address. More...
 
void setSubject (const std::string &subject)
 Set (record) subject name. More...
 
void setTls (bool tls)
 Set (record) TLS usage. 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...
 
void resetCalloutHandle ()
 Reset callout handle. More...
 

Static Public Attributes

static bool recordBasicAuth_ = false
 Record basic auth. More...
 
static bool recordIssuer_ = false
 Record issuer name. More...
 
static bool recordSubject_ = false
 Access control parameters: Flags which indicate what information to record. 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

std::string basic_auth_
 Basic auth. More...
 
HttpRequestContextPtr context_
 Pointer to the HttpRequestContext holding parsed data. More...
 
std::string custom_
 Custom name. More...
 
std::string issuer_
 Issuer name. More...
 
Method method_
 HTTP method of the request. More...
 
std::string remote_
 Remote address. More...
 
std::set< Methodrequired_methods_
 Set of required HTTP methods. More...
 
std::string subject_
 Subject name. More...
 
bool tls_
 TLS usage. 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< HttpVersionrequired_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, HttpHeaderPtrHttpHeaderMap
 Map of HTTP headers indexed by lower case header names. More...
 

Detailed Description

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:

  • the remote address
  • the use of TLS
  • the first commonName of the SubjectName of the client certificate
  • the first commonName of the IssuerName of the client certificate
  • the user ID of the basic HTTP authentication
  • a custom value

Callouts are associated to the request.

Definition at line 57 of file request.h.

Member Enumeration Documentation

◆ Method

HTTP methods.

Enumerator
HTTP_GET 
HTTP_POST 
HTTP_HEAD 
HTTP_PUT 
HTTP_DELETE 
HTTP_OPTIONS 
HTTP_CONNECT 
HTTP_METHOD_UNKNOWN 

Definition at line 61 of file request.h.

Constructor & Destructor Documentation

◆ HttpRequest() [1/2]

isc::http::HttpRequest::HttpRequest ( )

Constructor for inbound HTTP request.

Definition at line 30 of file request.cc.

◆ HttpRequest() [2/2]

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.

Parameters
methodHTTP method, e.g. POST.
uriURI.
versionHTTP version.
host_headerHost header to be included in the request. The default is the empty Host header.
basic_authBasic HTTP authentication credential. The default is no authentication.

Definition at line 38 of file request.cc.

References context(), isc::http::HttpHeader::getName(), isc::http::HttpHeader::getValue(), isc::http::HttpVersion::major_, methodToString(), and isc::http::HttpVersion::minor_.

+ Here is the call graph for this function:

Member Function Documentation

◆ context()

const HttpRequestContextPtr& isc::http::HttpRequest::context ( ) const
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.

Returns
Pointer to the underlying HttpRequestContext.

Definition at line 98 of file request.h.

Referenced by HttpRequest(), and isc::http::PostHttpRequestJson::PostHttpRequestJson().

◆ create()

void isc::http::HttpRequest::create ( )
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.

Exceptions
HttpRequestErrorif 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(), finalize(), and isc::http::HttpRequestParser::initModel().

+ Here is the call graph for this function:

◆ finalize()

void isc::http::HttpRequest::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 136 of file request.cc.

References create(), isc::http::HttpMessage::created_, and isc::http::HttpMessage::finalized_.

+ Here is the call graph for this function:

◆ getBasicAuth()

std::string isc::http::HttpRequest::getBasicAuth ( ) const
inline

Returns recorded basic auth.

Returns
recorded basic auth.

Definition at line 223 of file request.h.

◆ getBody()

std::string isc::http::HttpRequest::getBody ( ) const
virtual

Returns HTTP message body as string.

Implements isc::http::HttpMessage.

Definition at line 167 of file request.cc.

References isc::http::HttpMessage::checkFinalized(), and context_.

Referenced by toString().

+ Here is the call graph for this function:

◆ getCustom()

std::string isc::http::HttpRequest::getCustom ( ) const
inline

Returns recorded custom name.

Returns
recorded custom name.

Definition at line 237 of file request.h.

◆ getIssuer()

std::string isc::http::HttpRequest::getIssuer ( ) const
inline

Returns recorded issuer name.

Returns
recorded issuer name.

Definition at line 209 of file request.h.

◆ getMethod()

HttpRequest::Method isc::http::HttpRequest::getMethod ( ) const

Returns HTTP method of the request.

Definition at line 155 of file request.cc.

References isc::http::HttpMessage::checkCreated(), and method_.

Referenced by toBriefString().

+ Here is the call graph for this function:

◆ getRemote()

std::string isc::http::HttpRequest::getRemote ( ) const
inline

Returns remote address.

Returns
remote address from HTTP connection getRemote method.

Definition at line 106 of file request.h.

◆ getSubject()

std::string isc::http::HttpRequest::getSubject ( ) const
inline

Returns recorded subject name.

Returns
recorded subject name.

Definition at line 195 of file request.h.

◆ getTls()

bool isc::http::HttpRequest::getTls ( ) const
inline

Access control parameters: get/set methods.

Returns recorded TLS usage.

Returns
recorded TLS usage.

Definition at line 181 of file request.h.

◆ getUri()

std::string isc::http::HttpRequest::getUri ( ) const

Returns HTTP request URI.

Definition at line 161 of file request.cc.

References isc::http::HttpMessage::checkCreated(), and context_.

Referenced by toBriefString().

+ Here is the call graph for this function:

◆ isPersistent()

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.

Returns
true if the client has requested persistent connection, false otherwise.

Definition at line 219 of file request.cc.

References isc::http::HttpMessage::getHeader(), isc::http::HttpMessage::getHttpVersion(), and isc::http::HttpVersion::HTTP_10().

+ Here is the call graph for this function:

◆ methodFromString()

HttpRequest::Method isc::http::HttpRequest::methodFromString ( std::string  method) const
protected

Converts HTTP method specified in textual format to Method.

Parameters
methodHTTP method specified in the textual format. This value is case insensitive.
Returns
HTTP method as enum.
Exceptions
HttpRequestErrorif unknown method specified.

Definition at line 241 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().

◆ methodToString()

std::string isc::http::HttpRequest::methodToString ( const HttpRequest::Method method) const
protected

Converts HTTP method to string.

Parameters
methodHTTP method specified as enum.
Returns
HTTP method as string.

Definition at line 263 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().

◆ requireHttpMethod()

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.

Parameters
methodHTTP method allowed for the request.

Definition at line 63 of file request.cc.

References required_methods_.

Referenced by isc::http::PostHttpRequest::PostHttpRequest().

◆ reset()

void isc::http::HttpRequest::reset ( )
virtual

◆ setBasicAuth()

void isc::http::HttpRequest::setBasicAuth ( const std::string &  basic_auth)
inline

Set (record) basic auth.

Parameters
basic_auththe basic auth.

Definition at line 230 of file request.h.

◆ setCustom()

void isc::http::HttpRequest::setCustom ( const std::string &  custom)
inline

Set (record) custom name.

Parameters
customthe custom name.

Definition at line 244 of file request.h.

◆ setIssuer()

void isc::http::HttpRequest::setIssuer ( const std::string &  issuer)
inline

Set (record) issuer name.

Parameters
issuerthe issuer name.

Definition at line 216 of file request.h.

◆ setRemote()

void isc::http::HttpRequest::setRemote ( const std::string &  remote)
inline

Set remote address.

Parameters
remoteRemote end-point address in textual form.

Definition at line 113 of file request.h.

◆ setSubject()

void isc::http::HttpRequest::setSubject ( const std::string &  subject)
inline

Set (record) subject name.

Parameters
subjectthe subject name.

Definition at line 202 of file request.h.

◆ setTls()

void isc::http::HttpRequest::setTls ( bool  tls)
inline

Set (record) TLS usage.

Parameters
tlsthe TLS usage.

Definition at line 188 of file request.h.

◆ toBriefString()

std::string isc::http::HttpRequest::toBriefString ( ) const

Returns HTTP method, URI and HTTP version as a string.

Definition at line 173 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().

+ Here is the call graph for this function:

◆ toString()

std::string isc::http::HttpRequest::toString ( ) const
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 183 of file request.cc.

References isc::http::HttpMessage::checkFinalized(), getBody(), isc::http::HttpMessage::getHeader(), isc::http::HttpMessage::headers_, and toBriefString().

+ Here is the call graph for this function:

Member Data Documentation

◆ basic_auth_

std::string isc::http::HttpRequest::basic_auth_
protected

Basic auth.

Definition at line 303 of file request.h.

◆ context_

HttpRequestContextPtr isc::http::HttpRequest::context_
protected

◆ custom_

std::string isc::http::HttpRequest::custom_
protected

Custom name.

Definition at line 306 of file request.h.

◆ issuer_

std::string isc::http::HttpRequest::issuer_
protected

Issuer name.

Definition at line 300 of file request.h.

◆ method_

Method isc::http::HttpRequest::method_
protected

HTTP method of the request.

Definition at line 284 of file request.h.

Referenced by create(), getMethod(), and reset().

◆ recordBasicAuth_

bool isc::http::HttpRequest::recordBasicAuth_ = false
static

Record basic auth.

Definition at line 258 of file request.h.

Referenced by isc::http::BasicHttpAuthConfig::checkAuth().

◆ recordIssuer_

bool isc::http::HttpRequest::recordIssuer_ = false
static

Record issuer name.

Definition at line 255 of file request.h.

Referenced by isc::http::HttpConnection::recordParameters().

◆ recordSubject_

bool isc::http::HttpRequest::recordSubject_ = false
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().

◆ remote_

std::string isc::http::HttpRequest::remote_
protected

Remote address.

Definition at line 291 of file request.h.

Referenced by isc::http::PostHttpRequestJson::parseBodyAsJson().

◆ required_methods_

std::set<Method> isc::http::HttpRequest::required_methods_
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().

◆ subject_

std::string isc::http::HttpRequest::subject_
protected

Subject name.

Definition at line 297 of file request.h.

◆ tls_

bool isc::http::HttpRequest::tls_
protected

TLS usage.

Definition at line 294 of file request.h.


The documentation for this class was generated from the following files: