Kea  1.9.9-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 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< Methodrequired_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< 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.

Callouts are associated to the request.

Definition at line 49 of file request.h.

Member Enumeration Documentation

HTTP methods.

Enumerator
HTTP_GET 
HTTP_POST 
HTTP_HEAD 
HTTP_PUT 
HTTP_DELETE 
HTTP_OPTIONS 
HTTP_CONNECT 
HTTP_METHOD_UNKNOWN 

Definition at line 53 of file request.h.

Constructor & Destructor Documentation

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.

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

+ Here is the call graph for this function:

Member Function Documentation

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 90 of file request.h.

References context_.

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

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

+ Here is the call graph for this function:

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 126 of file request.cc.

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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 209 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:

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

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

Parameters
methodHTTP method allowed for the request.

Definition at line 53 of file request.cc.

References required_methods_.

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

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

+ Here is the call graph for this function:

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 173 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

HttpRequestContextPtr isc::http::HttpRequest::context_
protected
Method isc::http::HttpRequest::method_
protected

HTTP method of the request.

Definition at line 177 of file request.h.

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

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 174 of file request.h.

Referenced by create(), and requireHttpMethod().


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