mod_servlet
C++Servlets
 All Classes Files Functions Variables Typedefs Macros Pages
servlet::http_request Class Referenceabstract

Defines an object to provide client request information to a servlet. More...

#include <request.h>

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

Public Member Functions

virtual tree_any_mapget_attributes ()=0
 Returns the attributes map associated with this request. More...
 
virtual const tree_any_mapget_attributes () const =0
 Const version of call get_attributes() const. More...
 
virtual const std::map
< std::string, std::vector
< std::string >, std::less<> > & 
get_parameters ()=0
 Returns all the parameters of this request. More...
 
virtual const std::map
< string_view, string_view,
std::less<> > & 
get_env ()=0
 Returns all the environment variables accessible from this request. More...
 
virtual bool is_secure ()=0
 Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. More...
 
virtual std::shared_ptr
< SSL_information
ssl_information ()=0
 Returns information about SSL connection if it is established. 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...
 
virtual string_view get_auth_type ()=0
 Returns the name of the authentication scheme used to protect the servlet. More...
 
virtual const std::vector
< cookie > & 
get_cookies ()=0
 Returns an array containing all of the cookie objects the client sent with this request. More...
 
virtual string_view get_context_path () const =0
 Returns the portion of the request URI that indicates the context of the request. More...
 
virtual string_view get_servlet_path () const =0
 Returns the part of this request's URL that calls the servlet. More...
 
virtual const URIget_request_uri () const =0
 Returns the URI> with which this request was called. More...
 
virtual string_view get_path_info () const =0
 Returns any extra path information associated with the URL the client sent when it made this request. More...
 
virtual string_view get_header (const std::string &name) const =0
 Returns the value of the specified request header as a std::string. More...
 
virtual long get_date_header (const std::string &name) const =0
 Returns the value of the specified request header as a long value that represents a Date object. More...
 
virtual string_view get_content_type () const =0
 Returns the MIME type of the body of the request, or empty string if the type is not known. More...
 
virtual long get_content_length () const =0
 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...
 
virtual void get_headers (const std::string &name, std::vector< std::string > &headers) const =0
 Fills the std::vector with all the header values associated with the specified header name. More...
 
virtual void get_headers (std::vector< std::pair< std::string, std::string >> &headers) const =0
 Fills the std::vector with all the request header values. More...
 
virtual string_view get_method () const =0
 Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. More...
 
virtual string_view get_path_translated () const =0
 Returns any extra path information after the servlet name but before the query string, and translates it to a real path. More...
 
virtual string_view get_scheme () const =0
 Returns the name of the scheme used to make this request, for example, http or https. More...
 
virtual string_view get_protocol () const =0
 Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1. More...
 
virtual string_view get_client_addr () const =0
 Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. More...
 
virtual string_view get_client_host () const =0
 Returns the fully qualified name of the client or the last proxy that sent the request if available. More...
 
virtual uint16_t get_client_port () const =0
 Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request. More...
 
virtual string_view get_remote_user () const =0
 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...
 
virtual string_view get_local_addr () const =0
 Returns the Internet Protocol (IP) address of the interface on which the request was received. More...
 
virtual string_view get_local_host () const =0
 Returns the host name of the Internet Protocol (IP) interface on which the request was received. More...
 
virtual uint16_t get_local_port () const =0
 Returns the Internet Protocol (IP) port number of the interface on which the request was received. More...
 
virtual string_view get_server_name () const =0
 Returns the host name of the server to which the request was sent. More...
 
virtual uint16_t get_server_port () const =0
 Returns the port number to which the request was sent. More...
 
virtual void forward (const std::string &redirectURI, bool from_context_path=true)=0
 Redirects the request to a specified local URI within the server. More...
 
virtual int include (const std::string &includeURI, bool from_context_path=true)=0
 Includes the response of the specified local URI into the current response. More...
 
virtual http_sessionget_session ()=0
 Returns the current http_session associated with this request or, if there is no current session returns a new session. More...
 
virtual bool has_session ()=0
 Returns true if the http_session associated with this request exists. More...
 
virtual void invalidate_session ()=0
 Invalidates the session assosiated with this request if it exists.
 
virtual std::istream & get_input_stream ()=0
 Retrieves the body of the request as binary data using a std::istream. More...
 
virtual multipart_inputget_multipart_input ()=0
 Retrieves the body of the request as binary data if the input is a multipart stream. More...
 
virtual bool is_multipart () const =0
 Returns true if current request is multipart. More...
 

Detailed Description

Defines an object to provide client request information to a servlet.

The servlet container creates a http_equest object and passes it as an argument to the servlet's http_servlet::service method.

A http_request object provides data including parameter name and values, attributes,

Member Function Documentation

virtual void servlet::http_request::forward ( const std::string &  redirectURI,
bool  from_context_path = true 
)
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual tree_any_map& servlet::http_request::get_attributes ( )
pure virtual

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.

Implemented in servlet::http_request_wrapper.

virtual const tree_any_map& servlet::http_request::get_attributes ( ) const
pure virtual

Const version of call get_attributes() const.

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

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_auth_type ( )
pure virtual

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.

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_client_addr ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_client_host ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual uint16_t servlet::http_request::get_client_port ( ) const
pure virtual

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

Returns
an integer specifying the port number

Implemented in servlet::http_request_wrapper.

virtual long servlet::http_request::get_content_length ( ) const
pure virtual

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.

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_content_type ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_context_path ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual const std::vector<cookie>& servlet::http_request::get_cookies ( )
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual long servlet::http_request::get_date_header ( const std::string &  name) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual const std::map<string_view, string_view, std::less<> >& servlet::http_request::get_env ( )
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_header ( const std::string &  name) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual void servlet::http_request::get_headers ( const std::string &  name,
std::vector< std::string > &  headers 
) const
pure virtual

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.

Implemented in servlet::http_request_wrapper.

virtual void servlet::http_request::get_headers ( std::vector< std::pair< std::string, std::string >> &  headers) const
pure virtual

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

Parameters
headersThe values for all the header values.

Implemented in servlet::http_request_wrapper.

virtual std::istream& servlet::http_request::get_input_stream ( )
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_local_addr ( ) const
pure virtual

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.

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_local_host ( ) const
pure virtual

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.

Implemented in servlet::http_request_wrapper.

virtual uint16_t servlet::http_request::get_local_port ( ) const
pure virtual

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

Returns
an integer specifying the port number

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_method ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual multipart_input& servlet::http_request::get_multipart_input ( )
pure virtual

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

Implemented in servlet::http_request_wrapper.

template<typename StringType >
const optional_ref<const std::string> servlet::http_request::get_parameter ( const StringType &  name)
inline

Returns the value of a request parameter as a reference to std::string, or null if the parameter does not exist.

You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use get_parameters(const StringType&).

If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned by get_parameters.

Template Parameters
StringTypea type comparable to std::string
Parameters
namea StringType (might be std::string, string_view or const char*) specifying the name of the parameter
Returns
a reference to a std::string representing the single value of the parameter
See Also
get_parameters()
get_parameters(const StringType&)
virtual const std::map<std::string, std::vector<std::string>, std::less<> >& servlet::http_request::get_parameters ( )
pure virtual

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

Implemented in servlet::http_request_wrapper.

template<typename StringType >
const optional_ref<const std::vector<std::string> > servlet::http_request::get_parameters ( const StringType &  name)
inline

Returns all values of a request parameter as a reference to std::vector, or null if the parameters do not exist.

Template Parameters
StringTypea type comparable to std::string
Parameters
namea StringType (might be std::string, string_view or const char*) specifying the name of the parameter
Returns
a reference to a std::vector representing all the values of the parameter
See Also
get_parameters()
get_parameter(const StringType&)
virtual string_view servlet::http_request::get_path_info ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_path_translated ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_protocol ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_remote_user ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual const URI& servlet::http_request::get_request_uri ( ) const
pure virtual

Returns the URI> with which this request was called.

Returns
full request URI

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_scheme ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_server_name ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual uint16_t servlet::http_request::get_server_port ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual string_view servlet::http_request::get_servlet_path ( ) const
pure virtual

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.

Implemented in servlet::http_request_wrapper.

virtual http_session& servlet::http_request::get_session ( )
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual bool servlet::http_request::has_session ( )
pure virtual

Returns true if the http_session associated with this request exists.

Returns
the true if session associated with this request exists.

Implemented in servlet::http_request_wrapper.

virtual int servlet::http_request::include ( const std::string &  includeURI,
bool  from_context_path = true 
)
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual bool servlet::http_request::is_multipart ( ) const
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual bool servlet::http_request::is_secure ( )
pure virtual

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

Implemented in servlet::http_request_wrapper.

virtual std::shared_ptr<SSL_information> servlet::http_request::ssl_information ( )
pure virtual

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

Implemented in servlet::http_request_wrapper.


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