17#include <boost/pointer_cast.hpp>
29struct HttpCommandHooks {
30 int hook_index_http_auth_;
31 int hook_index_http_response_;
60 HttpResponsePtr response = createStockHttpResponseInternal(request, status_code);
66HttpCommandResponseCreator::
73 HttpVersion http_version(request->context()->http_version_major_,
74 request->context()->http_version_minor_);
78 http_version.major_ = 1;
79 http_version.minor_ = 0;
91HttpCommandResponseCreator::createDynamicHttpResponse(
HttpRequestPtr request) {
97 headers = config_->getHttpHeaders();
100 http_response = auth->checkAuth(*
this, request);
105 bool auth_failed =
false;
112 bool reset_handle =
false;
119 callout_handle->setArgument(
"request", request);
120 callout_handle->setArgument(
"response", http_response);
125 callout_handle->getArgument(
"request", request);
126 callout_handle->getArgument(
"response", http_response);
138 if (!auth_failed && !headers.empty()) {
140 if (http_response->isFinalized()) {
142 http_response->reset();
143 http_response->finalize();
146 return (http_response);
151 request->resetCalloutHandle();
161 boost::dynamic_pointer_cast<PostHttpRequestJson>(request);
185 if ((!config_ || config_->getEmulateAgentResponse()) &&
188 response_list->add(boost::const_pointer_cast<Element>(response));
189 response = response_list;
193 http_response = boost::dynamic_pointer_cast<
194 HttpResponseJson>(createStockHttpResponseInternal(request, HttpStatusCode::OK));
196 http_response->finalize();
205 callout_handle->setArgument(
"request", request);
206 callout_handle->setArgument(
"response", http_response);
211 callout_handle->getArgument(
"response", http_response);
216 return (http_response);
static CommandMgr & instance()
CommandMgr is a singleton class.
virtual http::HttpRequestPtr createNewHttpRequest() const
Create a new request.
virtual http::HttpResponsePtr createStockHttpResponse(const http::HttpRequestPtr &request, const http::HttpStatusCode &status_code) const
Creates stock HTTP response.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
@ NEXT_STEP_CONTINUE
continue normally
static int registerHook(const std::string &name)
Register Hook.
static bool calloutsPresent(int index)
Are callouts present?
static void callCallouts(int index, CalloutHandle &handle)
Calls the callouts for a given hook.
Wrapper class around callout handle which automatically resets handle's state.
Represents HTTP response with JSON content.
void setBodyAsJson(const data::ConstElementPtr &json_body)
Generates JSON content from the data structures represented as data::ConstElementPtr.
Represents HTTP POST request with JSON body.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
HttpStatusCode
HTTP status codes (cf RFC 2068)
void copyHttpHeaders(const CfgHttpHeaders &headers, const HTTP_MSG &message)
Copy config HTTP headers to message.
boost::shared_ptr< PostHttpRequestJson > PostHttpRequestJsonPtr
Pointer to PostHttpRequestJson.
boost::shared_ptr< HttpAuthConfig > HttpAuthConfigPtr
Type of shared pointers to HTTP authentication configuration.
boost::shared_ptr< HttpResponseJson > HttpResponseJsonPtr
Pointer to the HttpResponseJson object.
boost::shared_ptr< HttpResponse > HttpResponsePtr
Pointer to the HttpResponse object.
boost::shared_ptr< HttpRequest > HttpRequestPtr
Pointer to the HttpRequest object.
std::vector< CfgHttpHeader > CfgHttpHeaders
Collection of config HTTP headers.
Defines the logger used by the top-level component of kea-lfc.