Kea 2.5.8
isc::http::HttpRequest Class Reference

Represents HTTP request message. More...

#include <request.h>

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

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 HttpRequestContextPtrcontext () 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.
 
virtual void create ()=0
 Reads parsed message from the context, validates the message and stores parsed information.
 
virtual void finalize ()=0
 Complete parsing HTTP message or creating an HTTP outbound message.
 
virtual std::string getBody () const =0
 Returns HTTP message body as string.
 
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.
 
virtual void reset ()=0
 Reset the state of the object.
 
void setDirection (const Direction &direction)
 Sets direction for the HTTP message.
 
virtual std::string toString () const =0
 Returns HTTP message as text.
 
- 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< Methodrequired_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< HttpVersionrequired_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, HttpHeaderPtrHttpHeaderMap
 Map of HTTP headers indexed by lower case header names.
 

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

enum class isc::http::HttpRequest::Method
strong

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(), methodToString(), and version().

+ 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.

References context_.

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(), and finalize().

+ 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 132 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.

References basic_auth_.

◆ getBody()

std::string isc::http::HttpRequest::getBody ( ) const
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().

+ 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.

References custom_.

◆ 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.

References issuer_.

◆ getMethod()

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().

+ 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.

References remote_.

◆ 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.

References subject_.

◆ 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.

References tls_.

◆ getUri()

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().

+ 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 214 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 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().

◆ 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 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().

◆ 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

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().

◆ 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.

References basic_auth_.

◆ 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.

References custom_.

◆ 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.

References issuer_.

◆ 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.

References remote_.

◆ 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.

References subject_.

◆ 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.

References tls_.

◆ toBriefString()

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().

+ 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 179 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.

Referenced by getBasicAuth(), and setBasicAuth().

◆ 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.

Referenced by getCustom(), and setCustom().

◆ issuer_

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

Issuer name.

Definition at line 300 of file request.h.

Referenced by getIssuer(), and setIssuer().

◆ 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 getRemote(), isc::http::PostHttpRequestJson::parseBodyAsJson(), and setRemote().

◆ 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.

Referenced by getSubject(), and setSubject().

◆ tls_

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

TLS usage.

Definition at line 294 of file request.h.

Referenced by getTls(), and setTls().


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