mod_servlet
C++Servlets
|
Provides a convenient implementation of the http_request interface that can be subclassed by developers wishing to adapt the request to a http_servlet. More...
#include <request.h>
Public Member Functions | |
http_request_wrapper (http_request &req) | |
Constructs a request object wrapping the given request. More... | |
http_request & | get_wrapped_request () |
Returns wrapped request innstance. More... | |
const http_request & | get_wrapped_request () const |
Returns wrapped request innstance. More... | |
tree_any_map & | get_attributes () override |
Returns the attributes map associated with this request. More... | |
const tree_any_map & | get_attributes () const override |
Const version of call get_attributes() const. More... | |
const std::map< std::string, std::vector< std::string > , std::less<> > & | get_parameters () override |
Returns all the parameters of this request. More... | |
const std::map< string_view, string_view, std::less<> > & | get_env () override |
Returns all the environment variables accessible from this request. More... | |
bool | is_secure () override |
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. More... | |
std::shared_ptr< SSL_information > | ssl_information () override |
Returns information about SSL connection if it is established. More... | |
string_view | get_auth_type () override |
Returns the name of the authentication scheme used to protect the servlet. More... | |
const std::vector< cookie > & | get_cookies () override |
Returns an array containing all of the cookie objects the client sent with this request. More... | |
string_view | get_context_path () const override |
Returns the portion of the request URI that indicates the context of the request. More... | |
string_view | get_servlet_path () const override |
Returns the part of this request's URL that calls the servlet. More... | |
const URI & | get_request_uri () const override |
Returns the URI> with which this request was called. More... | |
string_view | get_path_info () const override |
Returns any extra path information associated with the URL the client sent when it made this request. More... | |
string_view | get_header (const std::string &name) const override |
Returns the value of the specified request header as a std::string . More... | |
long | get_date_header (const std::string &name) const override |
Returns the value of the specified request header as a long value that represents a Date object. More... | |
string_view | get_content_type () const override |
Returns the MIME type of the body of the request, or empty string if the type is not known. More... | |
long | get_content_length () const override |
Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known. More... | |
void | get_headers (const std::string &name, std::vector< std::string > &headers) const override |
Fills the std::vector with all the header values associated with the specified header name. More... | |
void | get_headers (std::vector< std::pair< std::string, std::string >> &headers) const override |
Fills the std::vector with all the request header values. More... | |
string_view | get_method () const override |
Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. More... | |
string_view | get_path_translated () const override |
Returns any extra path information after the servlet name but before the query string, and translates it to a real path. More... | |
string_view | get_scheme () const override |
Returns the name of the scheme used to make this request, for example, http or https . More... | |
string_view | get_protocol () const override |
Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1. More... | |
string_view | get_client_addr () const override |
Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. More... | |
string_view | get_client_host () const override |
Returns the fully qualified name of the client or the last proxy that sent the request if available. More... | |
uint16_t | get_client_port () const override |
Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request. More... | |
string_view | get_remote_user () const override |
Returns the login of the user making this request, if the user has been authenticated, or empty view if the user has not been authenticated. More... | |
string_view | get_local_addr () const override |
Returns the Internet Protocol (IP) address of the interface on which the request was received. More... | |
string_view | get_local_host () const override |
Returns the host name of the Internet Protocol (IP) interface on which the request was received. More... | |
uint16_t | get_local_port () const override |
Returns the Internet Protocol (IP) port number of the interface on which the request was received. More... | |
uint16_t | get_server_port () const override |
Returns the port number to which the request was sent. More... | |
string_view | get_server_name () const override |
Returns the host name of the server to which the request was sent. More... | |
void | forward (const std::string &redirectURL, bool from_context_path=true) override |
Redirects the request to a specified local URI within the server. More... | |
int | include (const std::string &includeURL, bool from_context_path=true) override |
Includes the response of the specified local URI into the current response. More... | |
http_session & | get_session () override |
Returns the current http_session associated with this request or, if there is no current session returns a new session. More... | |
bool | has_session () override |
Returns true if the http_session associated with this request exists. More... | |
void | invalidate_session () override |
Invalidates the session assosiated with this request if it exists. | |
bool | is_multipart () const override |
Returns true if current request is multipart. More... | |
std::istream & | get_input_stream () override |
Retrieves the body of the request as binary data using a std::istream . More... | |
multipart_input & | get_multipart_input () override |
Retrieves the body of the request as binary data if the input is a multipart stream. More... | |
![]() | |
template<typename StringType > | |
const optional_ref< const std::string > | get_parameter (const StringType &name) |
Returns the value of a request parameter as a reference to std::string , or null if the parameter does not exist. More... | |
template<typename StringType > | |
const optional_ref< const std::vector< std::string > > | get_parameters (const StringType &name) |
Returns all values of a request parameter as a reference to std::vector , or null if the parameters do not exist. More... | |
Protected Member Functions | |
virtual in_filter * | filter () |
Provides input filter for the http_request::get_input_stream or http_request::get_multipart_input. More... | |
Provides a convenient implementation of the http_request interface that can be subclassed by developers wishing to adapt the request to a http_servlet.
This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped request object.
This wrapper also provides filter method to filter std::istream
of the wrapped http_request.
|
inline |
Constructs a request object wrapping the given request.
req | The request to wrap |
|
inlineprotectedvirtual |
Provides input filter for the http_request::get_input_stream or http_request::get_multipart_input.
If this method returns valid in_filter it will be applied to std::istream
returned by get_input_stream method or to multipart_input
returned by get_multipart_input method. It also can return nullptr
in which case std::istream
will be returned without any filtering applied.
This method is called only once on the initialization of request input stream. This filter will be automatically deleted on destruction of the request object.
nullptr
|
inlineoverridevirtual |
Redirects the request to a specified local URI within the server.
Redirect processed internally without returning to the client, which is the difference of this method from http_response::send_redirect. This method expects only local path, not the full URI.
If the provided URI is an absolute path it will be used as is if from_context_path
argument is false
. Otherwise current context path will be prepended to the URI.
If the provided URI is a relative path it will be resolved against current request URI (see get_request_uri).
redirectURI | URI to redirect the request to |
from_context_path | true if the redirectURI should be resolved against the current context path |
Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the attributes map associated with this request.
Attributes can be set two ways. The servlet container may set attributes to make available custom information about a request. For example, for requests made using HTTPS, the attribute javax.servlet.request.X509Certificate
can be used to retrieve information on the certificate of the client. Attributes can also be set programatically using the returned map.
tree_any_map
containing the attributes of this request. Implements servlet::http_request.
|
inlineoverridevirtual |
Const version of call get_attributes() const.
tree_any_map
containing the attributes of this request. Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the name of the authentication scheme used to protect the servlet.
All servlet containers support basic, form and client certificate authentication, and may additionally support digest authentication. If the servlet is not authenticated empty string is returned.
Same as the value of the CGI variable AUTH_TYPE.
Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.
For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR
.
string_view
containing the IP address of the client that sent the request Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the fully qualified name of the client or the last proxy that sent the request if available.
If the engine cannot or chooses not to resolve the hostname, this method returns the dotted-string form of the IP address. For HTTP servlets, same as the value of the CGI variable REMOTE_HOST
.
string_view
containing the fully qualified name of the client Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.
Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known.
For HTTP servlets, same as the value of the CGI variable CONTENT_LENGTH.
Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the MIME type of the body of the request, or empty string if the type is not known.
For HTTP servlets, same as the value of the CGI variable CONTENT_TYPE.
string_view
containing the name of the MIME type of the request, or empty view if the type is not known Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the portion of the request URI that indicates the context of the request.
The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.
string_view
specifying the portion of the request URI that indicates the context of the request Implements servlet::http_request.
|
inlineoverridevirtual |
Returns an array containing all of the cookie
objects the client sent with this request.
This method returns empty vector if no cookies were sent.
cookies
included with this request, or empty vector if the request has no cookies Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the value of the specified request header as a long
value that represents a Date
object.
Use this method with headers that contain dates, such as If-Modified-Since
.
The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive.
If the request did not have a header of the specified name, this method returns -1. If the header can't be converted to a date, the method throws an stack_bad_cast
.
name | a std::string specifying the name of the header |
long
value representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT, or -1 if the named header was not included with the request stack_bad_cast | If the header value can't be converted to a date |
Implements servlet::http_request.
|
inlineoverridevirtual |
Returns all the environment variables accessible from this request.
Environment variables can be set by other servler modules in order to provide information to other modules (like PHP or CGI). This method allows to access these variables
tree_map
representing this request's environment variables Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the value of the specified request header as a std::string
.
If the request did not include a header of the specified name, this method returns empty string. If there are multiple headers with the same name, this method returns the first head in the request. The header name is case insensitive. You can use this method with any request header.
name | a std::string specifying the header name |
string_view
containing the value of the requested header, or empty view if the request does not have a header of that name Implements servlet::http_request.
|
inlineoverridevirtual |
Fills the std::vector
with all the header values associated with the specified header name.
name | Header name to look up |
headers | The values for the specified header. These are the raw values so if multiple values are specified in a single header that will be returned as a single header value. |
Implements servlet::http_request.
|
inlineoverridevirtual |
Fills the std::vector
with all the request header values.
headers | The values for all the header values. |
Implements servlet::http_request.
|
overridevirtual |
Retrieves the body of the request as binary data using a std::istream
.
If this request has content type of "multipart/form-data" method get_multipart_input also can be called. If get_multipart_input has already been called than get_input_stream
will return the input stream for the current part of the multipart stream.
std::istream
object containing the body of the request Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the Internet Protocol (IP) address of the interface on which the request was received.
string_view
containing the IP address on which the request was received. Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the host name of the Internet Protocol (IP) interface on which the request was received.
string_view
containing the host name of the IP on which the request was received. Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the Internet Protocol (IP) port number of the interface on which the request was received.
Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
Same as the value of the CGI variable REQUEST_METHOD.
string_view
specifying the name of the method with which this request was made Implements servlet::http_request.
|
overridevirtual |
Retrieves the body of the request as binary data if the input is a multipart stream.
This method can only retrieve input only if the current request has content type of "multipart/form-data". It it not so use method get_input_stream to read the request's input, while this method will throw stack_io_exception
.
If this method is called after calling get_input_stream stack_io_exception
will be thrown.
std::istream
object containing the body of the request stack_io_exception | if this request is not a multipart or if the stream is already retrieved with get_input_stream |
Implements servlet::http_request.
|
inlineoverridevirtual |
Returns all the parameters of this request.
Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body directly via get_input_stream or get_multipart_input can interfere with the execution of this method.
tree_map
representing this request's parameters Implements servlet::http_request.
|
inlineoverridevirtual |
Returns any extra path information associated with the URL the client sent when it made this request.
The extra path information follows the servlet path but precedes the query string and will start with a "/" character.
This method returns empty view if there was no extra path information.
Same as the value of the CGI variable PATH_INFO.
string_view
, decoded by the web container, specifying extra path information that comes after the servlet path but before the query string in the request URL; or empty view if the URL does not have any extra path information Implements servlet::http_request.
|
inlineoverridevirtual |
Returns any extra path information after the servlet name but before the query string, and translates it to a real path.
Same as the value of the CGI variable PATH_TRANSLATED.
If the URL does not have any extra path information, this method returns empty view or the servlet container cannot translate the virtual path to a real path for any reason (such as when the web application is executed from an archive). The web container does not decode this string.
string_view
specifying the real path, or empty view if the URL does not have any extra path information Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
For HTTP servlets, the value returned is the same as the value of the CGI variable SERVER_PROTOCOL
.
string_view
containing the protocol name and version number Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the login of the user making this request, if the user has been authenticated, or empty view if the user has not been authenticated.
Whether the user name is sent with each subsequent request depends on the browser and type of authentication. Same as the value of the CGI variable REMOTE_USER.
string_view
specifying the login of the user making this request, or empty view if the user login is not known Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the URI>
with which this request was called.
URI
Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the name of the scheme used to make this request, for example, http
or https
.
Different schemes have different rules for constructing URLs, as noted in RFC 1738.
string_view
containing the name of the scheme used to make this request Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the host name of the server to which the request was sent.
It is the value of the part before ":" in the Host
header value, if any, or the resolved server name, or the server IP address.
string_view
containing the name of the server Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the port number to which the request was sent.
It is the value of the part after ":" in the Host
header value, if any, or the server port where the client connection was accepted on.
Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the part of this request's URL that calls the servlet.
This path starts with a "/" character and includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string. Same as the value of the CGI variable SCRIPT_NAME.
This method will return an empty string ("") if the servlet used to process this request was matched using the wildcard pattern.
string_view
containing the name or path of the servlet being called, as specified in the request URL, decoded, or an empty string if the servlet used to process the request is matched using the wildcard pattern. Implements servlet::http_request.
|
inlineoverridevirtual |
Returns the current http_session
associated with this request or, if there is no current session returns a new session.
To make sure the session is properly maintained, you must call this method before the response is committed. If the container is using cookies to maintain session integrity.
If the intent is to get only the session which already exists use method has_session() to ensure the session exists before calling this method.
http_session
associated with this request. Implements servlet::http_request.
|
inline |
Returns wrapped request innstance.
|
inline |
Returns wrapped request innstance.
|
inlineoverridevirtual |
Returns true
if the http_session
associated with this request exists.
true
if session associated with this request exists. Implements servlet::http_request.
|
inlineoverridevirtual |
Includes the response of the specified local URI into the current response.
Include processed internally and locally. The provided URI follows the same rules as redirectURI
in forward call.
includeURI | URI to include into current response |
from_context_path | true if the includeURI should be resolved against the current context path |
Implements servlet::http_request.
|
inlineoverridevirtual |
Returns true
if current request is multipart.
This method should be called before calling get_multipart_input to avoid exceptions. If this method returns false
get_input_stream should be called instead.
true
if current request is multipart. Implements servlet::http_request.
|
inlineoverridevirtual |
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
Implements servlet::http_request.
|
inlineoverridevirtual |
Returns information about SSL connection if it is established.
SSL information will be provided only if this request was made using secure channel (method is_secure() returns true
. If Otherwise nullptr
will be returned.
nullptr
Implements servlet::http_request.