mod_servlet
C++Servlets
 All Classes Files Functions Variables Typedefs Macros Pages
servlet::http_request_wrapper Class Reference

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>

Inheritance diagram for servlet::http_request_wrapper:
servlet::http_request

Public Member Functions

 http_request_wrapper (http_request &req)
 Constructs a request object wrapping the given request. More...
 
http_requestget_wrapped_request ()
 Returns wrapped request innstance. More...
 
const http_requestget_wrapped_request () const
 Returns wrapped request innstance. More...
 
tree_any_mapget_attributes () override
 Returns the attributes map associated with this request. More...
 
const tree_any_mapget_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_informationssl_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 URIget_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_sessionget_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_inputget_multipart_input () override
 Retrieves the body of the request as binary data if the input is a multipart stream. More...
 
- Public Member Functions inherited from servlet::http_request
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_filterfilter ()
 Provides input filter for the http_request::get_input_stream or http_request::get_multipart_input. More...
 

Detailed Description

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.

See Also
http_request

Constructor & Destructor Documentation

servlet::http_request_wrapper::http_request_wrapper ( http_request req)
inline

Constructs a request object wrapping the given request.

Parameters
reqThe request to wrap

Member Function Documentation

virtual in_filter* servlet::http_request_wrapper::filter ( )
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.

Returns
an in_filter to apply to http_request input or nullptr
See Also
http_request::get_input_stream
http_request::get_multipart_input
void servlet::http_request_wrapper::forward ( const std::string &  redirectURI,
bool  from_context_path = true 
)
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).

Parameters
redirectURIURI to redirect the request to
from_context_pathtrue if the redirectURI should be resolved against the current context path
See Also
http_response::send_redirect
get_request_uri

Implements servlet::http_request.

tree_any_map& servlet::http_request_wrapper::get_attributes ( )
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.

Returns
an tree_any_map containing the attributes of this request.

Implements servlet::http_request.

const tree_any_map& servlet::http_request_wrapper::get_attributes ( ) const
inlineoverridevirtual

Const version of call get_attributes() const.

Returns
an const tree_any_map containing the attributes of this request.
See Also
get_attributes

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_auth_type ( )
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.

Returns
one of the static members BASIC_AUTH, FORM_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH (suitable for == comparison) or the container-specific string indicating the authentication scheme, or empty string if the request was not authenticated.

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_client_addr ( ) const
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.

Returns
a string_view containing the IP address of the client that sent the request

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_client_host ( ) const
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.

Returns
a string_view containing the fully qualified name of the client

Implements servlet::http_request.

uint16_t servlet::http_request_wrapper::get_client_port ( ) const
inlineoverridevirtual

Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.

Returns
an integer specifying the port number

Implements servlet::http_request.

long servlet::http_request_wrapper::get_content_length ( ) const
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.

Returns
an integer containing the length of the request body or -1 if the length is not known.

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_content_type ( ) const
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.

Returns
a 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.

string_view servlet::http_request_wrapper::get_context_path ( ) const
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.

Returns
a string_view specifying the portion of the request URI that indicates the context of the request

Implements servlet::http_request.

const std::vector<cookie>& servlet::http_request_wrapper::get_cookies ( )
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.

Returns
an array of all the cookies included with this request, or empty vector if the request has no cookies

Implements servlet::http_request.

long servlet::http_request_wrapper::get_date_header ( const std::string &  name) const
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.

Parameters
namea std::string specifying the name of the header
Returns
a 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
Exceptions
stack_bad_castIf the header value can't be converted to a date

Implements servlet::http_request.

const std::map<string_view, string_view, std::less<> >& servlet::http_request_wrapper::get_env ( )
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

Returns
a tree_map representing this request's environment variables

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_header ( const std::string &  name) const
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.

Parameters
namea std::string specifying the header name
Returns
a 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.

void servlet::http_request_wrapper::get_headers ( const std::string &  name,
std::vector< std::string > &  headers 
) const
inlineoverridevirtual

Fills the std::vector with all the header values associated with the specified header name.

Parameters
nameHeader name to look up
headersThe 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.

void servlet::http_request_wrapper::get_headers ( std::vector< std::pair< std::string, std::string >> &  headers) const
inlineoverridevirtual

Fills the std::vector with all the request header values.

Parameters
headersThe values for all the header values.

Implements servlet::http_request.

std::istream& servlet::http_request_wrapper::get_input_stream ( )
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.

Returns
a std::istream object containing the body of the request
See Also
get_multipart_input

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_local_addr ( ) const
inlineoverridevirtual

Returns the Internet Protocol (IP) address of the interface on which the request was received.

Returns
a string_view containing the IP address on which the request was received.

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_local_host ( ) const
inlineoverridevirtual

Returns the host name of the Internet Protocol (IP) interface on which the request was received.

Returns
a string_view containing the host name of the IP on which the request was received.

Implements servlet::http_request.

uint16_t servlet::http_request_wrapper::get_local_port ( ) const
inlineoverridevirtual

Returns the Internet Protocol (IP) port number of the interface on which the request was received.

Returns
an integer specifying the port number

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_method ( ) const
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.

Returns
a string_view specifying the name of the method with which this request was made

Implements servlet::http_request.

multipart_input& servlet::http_request_wrapper::get_multipart_input ( )
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.

Returns
a std::istream object containing the body of the request
Exceptions
stack_io_exceptionif this request is not a multipart or if the stream is already retrieved with get_input_stream
See Also
get_input_stream
multipart_input

Implements servlet::http_request.

const std::map<std::string, std::vector<std::string>, std::less<> >& servlet::http_request_wrapper::get_parameters ( )
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.

Returns
a tree_map representing this request's parameters
See Also
get_parameter
get_parameters(const StringType&)
get_input_stream
get_multipart_input

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_path_info ( ) const
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.

Returns
a 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.

string_view servlet::http_request_wrapper::get_path_translated ( ) const
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.

Returns
a string_view specifying the real path, or empty view if the URL does not have any extra path information

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_protocol ( ) const
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.

Returns
a string_view containing the protocol name and version number

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_remote_user ( ) const
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.

Returns
a 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.

const URI& servlet::http_request_wrapper::get_request_uri ( ) const
inlineoverridevirtual

Returns the URI> with which this request was called.

Returns
full request URI

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_scheme ( ) const
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.

Returns
a string_view containing the name of the scheme used to make this request

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_server_name ( ) const
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.

Returns
a string_view containing the name of the server

Implements servlet::http_request.

uint16_t servlet::http_request_wrapper::get_server_port ( ) const
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.

Returns
an integer specifying the port number

Implements servlet::http_request.

string_view servlet::http_request_wrapper::get_servlet_path ( ) const
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.

Returns
a 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.

http_session& servlet::http_request_wrapper::get_session ( )
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.

Returns
the http_session associated with this request.
See Also
has_session

Implements servlet::http_request.

http_request& servlet::http_request_wrapper::get_wrapped_request ( )
inline

Returns wrapped request innstance.

Returns
reference to wrapped request instance
const http_request& servlet::http_request_wrapper::get_wrapped_request ( ) const
inline

Returns wrapped request innstance.

Returns
const reference to wrapped request instance
bool servlet::http_request_wrapper::has_session ( )
inlineoverridevirtual

Returns true if the http_session associated with this request exists.

Returns
the true if session associated with this request exists.

Implements servlet::http_request.

int servlet::http_request_wrapper::include ( const std::string &  includeURI,
bool  from_context_path = true 
)
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.

Parameters
includeURIURI to include into current response
from_context_pathtrue if the includeURI should be resolved against the current context path
See Also
forward
http_response::send_redirect
get_request_uri

Implements servlet::http_request.

bool servlet::http_request_wrapper::is_multipart ( ) const
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.

Returns
true if current request is multipart.
See Also
get_multipart_input
get_input_stream

Implements servlet::http_request.

bool servlet::http_request_wrapper::is_secure ( )
inlineoverridevirtual

Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

Returns
a boolean indicating if the request was made using a secure channel

Implements servlet::http_request.

std::shared_ptr<SSL_information> servlet::http_request_wrapper::ssl_information ( )
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.

Returns
SSL_information of this connection or nullptr
See Also
is_secure
SSL_information

Implements servlet::http_request.


The documentation for this class was generated from the following file: