8 #ifndef SERVLET_SERVLET_H
9 #define SERVLET_SERVLET_H
18 #include <servlet/request.h>
19 #include <servlet/response.h>
20 #include <servlet/context.h>
27 #define SERVLET_EXPORT(factoryName, className) extern "C" servlet::http_servlet* factoryName() { return new className{}; }
190 template <
typename KeyType>
437 void _maybe_set_last_modified(
http_response &resp,
long lastModifiedSec);
439 static const std::string METHOD_DELETE;
440 static const std::string METHOD_HEAD;
441 static const std::string METHOD_GET;
442 static const std::string METHOD_OPTIONS;
443 static const std::string METHOD_POST;
444 static const std::string METHOD_PUT;
445 static const std::string METHOD_TRACE;
447 static const std::string HEADER_IFMODSINCE;
448 static const std::string HEADER_LASTMOD;
455 #endif // SERVLET_SERVLET_H
virtual void do_trace(http_request &req, http_response &resp)
Called by the server (via the service method) to allow a servlet to handle a TRACE request...
Defines an object to provide client request information to a servlet.
Definition: request.h:35
static constexpr int HEAD_ALLOWED
Constant to indicate that HEAD method is allowed.
Definition: servlet.h:406
static constexpr int DELETE_ALLOWED
Constant to indicate that DELETE method is allowed.
Definition: servlet.h:401
Optional reference implementation.
Definition: optional.h:221
virtual int get_allowed_methods()
This method is needed by do_options, which adds all allowed by the servlet methods.
Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site...
Definition: servlet.h:93
virtual void do_delete(http_request &req, http_response &resp)
Called by the server (via the service method) to allow a servlet to handle a DELETE request...
static constexpr int POST_ALLOWED
Constant to indicate that POST method is allowed.
Definition: servlet.h:391
optional_ref< const std::string > get_init_parameter(const KeyType &name) const
Returns an optional std::string containing the value of the named initialization parameter, or null if the parameter does not exist.
Definition: servlet.h:191
virtual void do_put(http_request &req, http_response &resp)
Called by the server (via the service method) to allow a servlet to handle a PUT request.
virtual long get_last_modified(http_request &req)
Returns the time the http_request object was last modified, in milliseconds since midnight January 1...
static constexpr int OPTIONS_ALLOWED
Constant to indicate that OPTIONS method is allowed.
Definition: servlet.h:416
virtual void do_post(http_request &req, http_response &resp)
Called by the server (via the service method) to allow a servlet to handle a POST request...
const std::map< std::string, std::string, std::less<> > & get_init_parameters() const
Returns the all of the servlet's initialization parameters as an tree_map of std::string objects...
Definition: servlet.h:174
virtual void do_head(http_request &req, http_response &resp)
const std::string & get_servlet_name() const
Returns the name of this servlet instance.
Definition: servlet.h:160
const std::string & get_servlet_name() const
Returns the name of this servlet instance.
Definition: context.h:272
static constexpr int TRACE_ALLOWED
Constant to indicate that TRACE method is allowed.
Definition: servlet.h:411
A servlet configuration object used by a servlet container to pass information to a servlet during in...
Definition: context.h:243
virtual void do_get(http_request &req, http_response &resp)
Called by the server (via the service method) to allow a servlet to handle a GET request.
const servlet_config & get_servlet_config() const
Returns a servlet_config object, which contains initialization and startup parameters for this servle...
Definition: servlet.h:150
static constexpr int PUT_ALLOWED
Constant to indicate that PUT method is allowed.
Definition: servlet.h:396
virtual void init()
A convenience method which can be overridden so that there's no need to call init(config).
Definition: servlet.h:125
const std::map< std::string, std::string, std::less<> > & get_init_parameters() const
Returns all the servlet's initialization parameters as a tree_map.
Definition: context.h:304
virtual void service(http_request &req, http_response &resp)
Receives standard HTTP requests from the public service method and dispatches them to the do_method m...
Defines an object to assist a servlet in sending a response to the client.
Definition: response.h:33
optional_ref< const std::string > get_init_parameter(const KeyType &key) const
Returns a std::string containing the value of the named initialization parameter, or empty_reference ...
Definition: context.h:295
virtual void do_options(http_request &req, http_response &resp)
Called by the server (via the service method) to allow a servlet to handle a OPTIONS request...
static constexpr int GET_ALLOWED
Constant to indicate that GET method is allowed.
Definition: servlet.h:386