Kea 2.7.5
|
Specifies an interface for classes creating HTTP responses from HTTP requests. More...
#include <response_creator.h>
Public Member Functions | |
virtual | ~HttpResponseCreator () |
Destructor. | |
virtual HttpResponsePtr | createHttpResponse (HttpRequestPtr request) final |
Create HTTP response from HTTP request received. | |
virtual HttpRequestPtr | createNewHttpRequest () const =0 |
Create a new request. | |
virtual HttpResponsePtr | createStockHttpResponse (const HttpRequestPtr &request, const HttpStatusCode &status_code) const =0 |
Creates implementation specific HTTP response. | |
Protected Member Functions | |
virtual HttpResponsePtr | createDynamicHttpResponse (HttpRequestPtr request)=0 |
Creates implementation specific HTTP response. | |
Specifies an interface for classes creating HTTP responses from HTTP requests.
HTTP is designed to carry various content types. Most commonly this is text/html. In Kea, the application/json content type is used to carry control commands in JSON format. The libkea-http library is meant to be generic and provide means for transferring different types of content, depending on the use case.
This abstract class specifies a common interface for generating HTTP responses from HTTP requests using specific content type and being used in some specific context. Kea modules providing HTTP services need to implement their specific derivations of the HttpResponseCreator class. These derivations use classes derived from HttpRequest as an input and classes derived from HttpResponse as an output of createHttpResponse
method.
Definition at line 38 of file response_creator.h.
|
inlinevirtual |
Destructor.
Classes with virtual functions need virtual destructors.
Definition at line 44 of file response_creator.h.
|
protectedpure virtual |
Creates implementation specific HTTP response.
request | Pointer to an object representing HTTP request. |
Referenced by createHttpResponse().
|
finalvirtual |
Create HTTP response from HTTP request received.
This class implements a generic logic for creating a HTTP response. Derived classes do not override this method. They merely implement the methods it calls.
The request processing may generally fail at one of the two stages: parsing or interpretation of the parsed request. During the former stage the request's syntax is checked, i.e. HTTP version, URI, headers etc. During the latter stage the HTTP server checks if the request is valid within the specific context, e.g. valid HTTP version used, expected content type etc.
In the HttpRequest terms, the request has gone through the first stage if it is "finalized" (see HttpRequest::finalize). This method accepts instances of both finalized and not finalized requests. If the request isn't finalized it indicates that the request parsing has failed. In such case, this method calls createStockBadRequest
to generate a response with HTTP 400 status code. If the request is finalized, this method calls createDynamicHttpResponse
to generate implementation specific response to the received request.
This method is marked virtual final to prevent derived classes from overriding this method. Instead, the derived classes must implement protected methods which this method calls.
request | Pointer to an object representing HTTP request. |
HttpResponseError | if request is a NULL pointer. |
Definition at line 15 of file response_creator.cc.
References isc::http::BAD_REQUEST, createDynamicHttpResponse(), createStockHttpResponse(), and isc_throw.
|
pure virtual |
Create a new request.
This method creates an instance of the HttpRequest or derived class. The type of the object is compatible with the instance of the HttpResponseCreator implementation which creates it, i.e. can be used as an argument in the call to createHttpResponse.
Implemented in isc::agent::CtrlAgentResponseCreator, isc::config::CmdResponseCreator, and isc::config::HttpCommandResponseCreator.
|
pure virtual |
Creates implementation specific HTTP response.
request | Pointer to an object representing HTTP request. |
status_code | Status code of the response. |
Implemented in isc::agent::CtrlAgentResponseCreator, isc::config::CmdResponseCreator, and isc::config::HttpCommandResponseCreator.
Referenced by createHttpResponse().