Kea 2.7.5
|
Represents HTTP POST request with JSON body. More...
#include <post_request_json.h>
Public Member Functions | |
PostHttpRequestJson () | |
Constructor for inbound HTTP request. | |
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. | |
virtual void | finalize () |
Complete parsing of the HTTP request. | |
data::ConstElementPtr | getBodyAsJson () const |
Retrieves JSON body. | |
data::ConstElementPtr | getJsonElement (const std::string &element_name) const |
Retrieves a single JSON element. | |
virtual void | reset () |
Reset the state of the object. | |
void | setBodyAsJson (const data::ConstElementPtr &body) |
Sets JSON body for an outbound message. | |
Public Member Functions inherited from isc::http::PostHttpRequest | |
PostHttpRequest () | |
Constructor for inbound HTTP request. | |
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. | |
Public Member Functions inherited from isc::http::HttpRequest | |
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. | |
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. | |
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. | |
Protected Member Functions | |
void | parseBodyAsJson () |
Interprets body as JSON, which can be later retrieved using data element objects. | |
Protected Member Functions inherited from isc::http::HttpRequest | |
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 | |
data::ConstElementPtr | json_ |
Pointer to the parsed JSON body. | |
Protected Attributes inherited from isc::http::HttpRequest | |
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 | |
Public Types inherited from isc::http::HttpRequest | |
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... | |
Static Public Attributes inherited from isc::http::HttpRequest | |
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 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 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.
|
explicit |
Constructor for inbound HTTP request.
Definition at line 16 of file post_request_json.cc.
References isc::http::HttpMessage::requireHeaderValue().
|
explicit |
Constructor for outbound HTTP request.
This constructor adds "Content-Type" header with the value of "application/json" to the context.
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 21 of file post_request_json.cc.
References isc::http::HttpRequest::context(), and isc::http::HttpMessage::requireHeaderValue().
|
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().
ConstElementPtr isc::http::PostHttpRequestJson::getBodyAsJson | ( | ) | const |
Retrieves JSON body.
HttpRequestJsonError | if an error occurred. |
Definition at line 49 of file post_request_json.cc.
References isc::http::HttpMessage::checkFinalized(), and json_.
Referenced by 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.
element_name | Element name. |
HttpRequestJsonError | if an error occurred. |
Definition at line 66 of file post_request_json.cc.
References getBodyAsJson(), isc_throw, and isc::Exception::what().
|
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::data::Element::create(), isc::data::Element::fromJSON(), isc_throw, json_, isc::data::Element::map, isc::http::HttpRequest::remote_, and isc::Exception::what().
Referenced by finalize().
|
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::HttpMessage::reset().
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.
body | JSON structure to be used as a body. |
Definition at line 55 of file post_request_json.cc.
References isc::http::HttpRequest::context_, and 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().