Kea  2.1.7-git
isc::http::PostHttpRequestJson Class Reference

Represents HTTP POST request with JSON body. More...

#include <post_request_json.h>

+ Inheritance diagram for isc::http::PostHttpRequestJson:

Public Member Functions

 PostHttpRequestJson ()
 Constructor for inbound HTTP request. More...
 
 PostHttpRequestJson (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...
 
virtual void finalize ()
 Complete parsing of the HTTP request. More...
 
data::ConstElementPtr getBodyAsJson () const
 Retrieves JSON body. More...
 
data::ConstElementPtr getJsonElement (const std::string &element_name) const
 Retrieves a single JSON element. More...
 
virtual void reset ()
 Reset the state of the object. More...
 
void setBodyAsJson (const data::ConstElementPtr &body)
 Sets JSON body for an outbound message. More...
 
- Public Member Functions inherited from isc::http::PostHttpRequest
 PostHttpRequest ()
 Constructor for inbound HTTP request. More...
 
 PostHttpRequest (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...
 
- Public Member Functions inherited from isc::http::HttpRequest
 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...
 
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...
 
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...
 

Protected Member Functions

void parseBodyAsJson ()
 Interprets body as JSON, which can be later retrieved using data element objects. More...
 
- Protected Member Functions inherited from isc::http::HttpRequest
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

data::ConstElementPtr json_
 Pointer to the parsed JSON body. More...
 
- Protected Attributes inherited from isc::http::HttpRequest
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

- Public Types inherited from isc::http::HttpRequest
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...
 
- Static Public Attributes inherited from isc::http::HttpRequest
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 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 POST request with JSON body.

In addition to the requirements specified by the PostHttpRequest this class requires that the "Content-Type" is "application/json".

This class provides methods to parse and retrieve JSON data structures.

Definition at line 37 of file post_request_json.h.

Constructor & Destructor Documentation

◆ PostHttpRequestJson() [1/2]

isc::http::PostHttpRequestJson::PostHttpRequestJson ( )
explicit

Constructor for inbound HTTP request.

Definition at line 16 of file post_request_json.cc.

References isc::http::HttpMessage::requireHeaderValue().

+ Here is the call graph for this function:

◆ PostHttpRequestJson() [2/2]

isc::http::PostHttpRequestJson::PostHttpRequestJson ( const Method method,
const std::string &  uri,
const HttpVersion version,
const HostHttpHeader host_header = HostHttpHeader(),
const BasicHttpAuthPtr basic_auth = BasicHttpAuthPtr() 
)
explicit

Constructor for outbound HTTP request.

This constructor adds "Content-Type" header with the value of "application/json" to the context.

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 21 of file post_request_json.cc.

References isc::http::HttpRequest::context(), and isc::http::HttpMessage::requireHeaderValue().

+ Here is the call graph for this function:

Member Function Documentation

◆ finalize()

void isc::http::PostHttpRequestJson::finalize ( )
virtual

Complete parsing of the HTTP request.

This method parses the JSON body into the structure of data::ConstElementPtr objects.

Reimplemented from isc::http::HttpRequest.

Definition at line 32 of file post_request_json.cc.

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

+ Here is the call graph for this function:

◆ getBodyAsJson()

ConstElementPtr isc::http::PostHttpRequestJson::getBodyAsJson ( ) const

Retrieves JSON body.

Returns
Pointer to the root element of the JSON structure.
Exceptions
HttpRequestJsonErrorif an error occurred.

Definition at line 49 of file post_request_json.cc.

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

Referenced by isc::agent::CtrlAgentResponseCreator::createStockHttpResponse(), isc::config::CmdResponseCreator::createStockHttpResponse(), and getJsonElement().

+ Here is the call graph for this function:

◆ getJsonElement()

ConstElementPtr isc::http::PostHttpRequestJson::getJsonElement ( const std::string &  element_name) const

Retrieves a single JSON element.

The element must be at top level of the JSON structure.

Parameters
element_nameElement name.
Returns
Pointer to the specified element or NULL if such element doesn't exist.
Exceptions
HttpRequestJsonErrorif an error occurred.

Definition at line 66 of file post_request_json.cc.

References getBodyAsJson(), isc_throw, and isc::Exception::what().

+ Here is the call graph for this function:

◆ parseBodyAsJson()

void isc::http::PostHttpRequestJson::parseBodyAsJson ( )
protected

Interprets body as JSON, which can be later retrieved using data element objects.

Definition at line 85 of file post_request_json.cc.

References isc::http::HttpRequest::context_, isc_throw, json_, isc::http::HttpRequest::remote_, and isc::Exception::what().

Referenced by finalize().

+ Here is the call graph for this function:

◆ reset()

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

Reset the state of the object.

Reimplemented from isc::http::HttpRequest.

Definition at line 43 of file post_request_json.cc.

References json_, and isc::http::HttpRequest::reset().

+ Here is the call graph for this function:

◆ setBodyAsJson()

void isc::http::PostHttpRequestJson::setBodyAsJson ( const data::ConstElementPtr body)

Sets JSON body for an outbound message.

Note that this method copies the pointer to the body, rather than the entire data structure. Thus, the original object should not be modified after this method is called. If the specified pointer is null, the empty body is set.

Parameters
bodyJSON structure to be used as a body.

Definition at line 55 of file post_request_json.cc.

References isc::http::HttpRequest::context_, and json_.

Member Data Documentation

◆ json_

data::ConstElementPtr isc::http::PostHttpRequestJson::json_
protected

Pointer to the parsed JSON body.

Definition at line 103 of file post_request_json.h.

Referenced by getBodyAsJson(), parseBodyAsJson(), reset(), and setBodyAsJson().


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