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

This class represents a multipart input stream of a multipart/form-data request body. More...

#include <request.h>

Public Member Functions

virtual const std::map
< std::string, std::vector
< std::string >, std::less<> > & 
get_headers () const =0
 Obtain all the headers of the curent part. More...
 
template<typename StringType >
optional_ref< const std::string > get_header (const StringType &name) const
 Obtains the value of the specified part header as a reference to a std::string. More...
 
template<typename StringType >
optional_ref< const
std::vector< std::string > > 
get_headers (const StringType &name) const
 Obtain all the values of the specified part header. More...
 
optional_ref< const std::string > get_content_type () const
 Obtain the content type passed by the browser. More...
 
optional_ref< const std::string > get_name () const
 Obtain the name of the field in the multipart form corresponding to this part. More...
 
optional_ref< const std::string > get_submitted_filename () const
 If this part represents an uploaded file, gets the file name submitted in the upload. More...
 
virtual std::istream & get_input_stream ()=0
 Obtain an std::itream that can be used to retrieve the contents of the current part. More...
 
virtual bool to_next_part ()=0
 Moves this multipart_input to the next part. More...
 

Detailed Description

This class represents a multipart input stream of a multipart/form-data request body.

Each part of this class may represent either an uploaded file or form data.

This class is built on top of input stream of a request and it doesn't cache any data.

The parts can be navigated only in forward direction using to_next_part method. The usual use of this class can be illustrated by the following code:

multipart_input in = request.get_multipart_input();
while (in.to_next_part())
{
optional_ref<const std::string> header_value = in.get_header("header-name");
if (header_value && *header_value == "expected-value")
{
std::istream& part_in = in.get_input_stream();
// process part_in
...
}
}

Member Function Documentation

optional_ref<const std::string> servlet::multipart_input::get_content_type ( ) const
inline

Obtain the content type passed by the browser.

Returns
The content type passed by the browser or null if not defined.
template<typename StringType >
optional_ref<const std::string> servlet::multipart_input::get_header ( const StringType &  name) const
inline

Obtains the value of the specified part header as a reference to a std::string.

If there are multiple headers with the same name, this method returns the first header in the part.

Template Parameters
StringTypea type comparable to std::string
Parameters
nameHeader name
Returns
The header value or empty reference if the header is not present
virtual const std::map<std::string, std::vector<std::string>, std::less<> >& servlet::multipart_input::get_headers ( ) const
pure virtual

Obtain all the headers of the curent part.

Returns
All the headers of the current part.
template<typename StringType >
optional_ref<const std::vector<std::string> > servlet::multipart_input::get_headers ( const StringType &  name) const
inline

Obtain all the values of the specified part header.

Template Parameters
StringTypea type comparable to std::string
Parameters
nameThe name of the header of interest.
Returns
All the values of the specified part header. If the part did not include any headers of the specified name, this method returns an empty std::vector.
virtual std::istream& servlet::multipart_input::get_input_stream ( )
pure virtual

Obtain an std::itream that can be used to retrieve the contents of the current part.

Returns
An std::istream for the contents of the current part
optional_ref<const std::string> servlet::multipart_input::get_name ( ) const
inline

Obtain the name of the field in the multipart form corresponding to this part.

Returns
The name of the field in the multipart form corresponding to this part.
optional_ref<const std::string> servlet::multipart_input::get_submitted_filename ( ) const

If this part represents an uploaded file, gets the file name submitted in the upload.

Returns empty reference if no file name is available or if this part is not a file upload.

Returns
the submitted file name or empty reference.
virtual bool servlet::multipart_input::to_next_part ( )
pure virtual

Moves this multipart_input to the next part.

Returns
true if the next part exists and readable, otherwise false

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