C++ Rest SDK
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Classes | Public Types | Public Member Functions | List of all members
web::http::http_headers Class Reference

Represents HTTP headers, acts like a map. More...

#include <http_headers.h>

Classes

struct  _case_insensitive_cmp
 Function object to perform case insensitive comparison of wstrings. More...
 

Public Types

typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::key_type key_type
 STL-style typedefs More...
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::key_compare key_compare
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::allocator_type allocator_type
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::size_type size_type
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::difference_type difference_type
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::pointer pointer
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::const_pointer const_pointer
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::reference reference
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::const_reference const_reference
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::iterator iterator
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::const_iterator const_iterator
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::reverse_iterator reverse_iterator
 
typedef std::map< utility::string_t, utility::string_t, _case_insensitive_cmp >::const_reverse_iterator const_reverse_iterator
 

Public Member Functions

 http_headers ()
 Constructs an empty set of HTTP headers. More...
 
 http_headers (const http_headers &other)
 Copy constructor. More...
 
http_headersoperator= (const http_headers &other)
 Assignment operator. More...
 
 http_headers (http_headers &&other)
 Move constructor. More...
 
http_headersoperator= (http_headers &&other)
 Move assignment operator. More...
 
template<typename _t1 >
void add (const key_type &name, const _t1 &value)
 Adds a header field using the '<<' operator. More...
 
void remove (const key_type &name)
 Removes a header field. More...
 
void clear ()
 Removes all elements from the headers. More...
 
bool has (const key_type &name) const
 Checks if there is a header with the given key. More...
 
size_type size () const
 Returns the number of header fields. More...
 
bool empty () const
 Tests to see if there are any header fields. More...
 
utility::string_t & operator[] (const key_type &name)
 Returns a reference to header field with given name, if there is no header field one is inserted. More...
 
iterator find (const key_type &name)
 Checks if a header field exists with given name and returns an iterator if found. Otherwise and iterator to end is returned. More...
 
const_iterator find (const key_type &name) const
 
template<typename _t1 >
bool match (const key_type &name, _t1 &value) const
 Attempts to match a header field with the given name using the '>>' operator. More...
 
iterator begin ()
 Returns an iterator referring to the first header field. More...
 
const_iterator begin () const
 
iterator end ()
 Returns an iterator referring to the past-the-end header field. More...
 
const_iterator end () const
 
_ASYNCRTIMP utility::size64_t content_length () const
 Gets the content length of the message. More...
 
_ASYNCRTIMP void set_content_length (utility::size64_t length)
 Sets the content length of the message. More...
 
_ASYNCRTIMP utility::string_t content_type () const
 Gets the content type of the message. More...
 
_ASYNCRTIMP void set_content_type (utility::string_t type)
 Sets the content type of the message. More...
 
_ASYNCRTIMP utility::string_t cache_control () const
 Gets the cache control header of the message. More...
 
_ASYNCRTIMP void set_cache_control (utility::string_t control)
 Sets the cache control header of the message. More...
 
_ASYNCRTIMP utility::string_t date () const
 Gets the date header of the message. More...
 
_ASYNCRTIMP void set_date (const utility::datetime &date)
 Sets the date header of the message. More...
 

Detailed Description

Represents HTTP headers, acts like a map.

Member Typedef Documentation

typedef std::map<utility::string_t, utility::string_t, _case_insensitive_cmp>::key_type web::http::http_headers::key_type

STL-style typedefs

Constructor & Destructor Documentation

web::http::http_headers::http_headers ( )
inline

Constructs an empty set of HTTP headers.

web::http::http_headers::http_headers ( const http_headers other)
inline

Copy constructor.

Parameters
otherAn http_headers object to copy from.
web::http::http_headers::http_headers ( http_headers &&  other)
inline

Move constructor.

Parameters
otherAn http_headers object to move.

Member Function Documentation

template<typename _t1 >
void web::http::http_headers::add ( const key_type name,
const _t1 &  value 
)
inline

Adds a header field using the '<<' operator.

Parameters
nameThe name of the header field.
valueThe value of the header field.

If the header field exists, the value will be combined as comma separated string.

iterator web::http::http_headers::begin ( )
inline

Returns an iterator referring to the first header field.

Returns
An iterator to the beginning of the HTTP headers
_ASYNCRTIMP utility::string_t web::http::http_headers::cache_control ( ) const

Gets the cache control header of the message.

Returns
The cache control header value.
void web::http::http_headers::clear ( )
inline

Removes all elements from the headers.

_ASYNCRTIMP utility::size64_t web::http::http_headers::content_length ( ) const

Gets the content length of the message.

Returns
The length of the content.
_ASYNCRTIMP utility::string_t web::http::http_headers::content_type ( ) const

Gets the content type of the message.

Returns
The content type of the body.
_ASYNCRTIMP utility::string_t web::http::http_headers::date ( ) const

Gets the date header of the message.

Returns
The date header value.
bool web::http::http_headers::empty ( ) const
inline

Tests to see if there are any header fields.

Returns
true if there are no headers, false otherwise.
iterator web::http::http_headers::end ( )
inline

Returns an iterator referring to the past-the-end header field.

Returns
An iterator to the element past the end of the HTTP headers.
iterator web::http::http_headers::find ( const key_type name)
inline

Checks if a header field exists with given name and returns an iterator if found. Otherwise and iterator to end is returned.

Parameters
nameThe name of the header field.
Returns
An iterator to where the HTTP header is found.
bool web::http::http_headers::has ( const key_type name) const
inline

Checks if there is a header with the given key.

Parameters
nameThe name of the header field.
Returns
true if there is a header with the given name, false otherwise.
template<typename _t1 >
bool web::http::http_headers::match ( const key_type name,
_t1 &  value 
) const
inline

Attempts to match a header field with the given name using the '>>' operator.

Parameters
nameThe name of the header field.
valueThe value of the header field.
Returns
true if header field was found and successfully stored in value parameter.
http_headers& web::http::http_headers::operator= ( const http_headers other)
inline

Assignment operator.

Parameters
otherAn http_headers object to copy from.
http_headers& web::http::http_headers::operator= ( http_headers &&  other)
inline

Move assignment operator.

Parameters
otherAn http_headers object to move.
utility::string_t& web::http::http_headers::operator[] ( const key_type name)
inline

Returns a reference to header field with given name, if there is no header field one is inserted.

void web::http::http_headers::remove ( const key_type name)
inline

Removes a header field.

Parameters
nameThe name of the header field.
_ASYNCRTIMP void web::http::http_headers::set_cache_control ( utility::string_t  control)

Sets the cache control header of the message.

Parameters
controlThe cache control header value.
_ASYNCRTIMP void web::http::http_headers::set_content_length ( utility::size64_t  length)

Sets the content length of the message.

Parameters
lengthThe length of the content.
_ASYNCRTIMP void web::http::http_headers::set_content_type ( utility::string_t  type)

Sets the content type of the message.

Parameters
typeThe content type of the body.
_ASYNCRTIMP void web::http::http_headers::set_date ( const utility::datetime date)

Sets the date header of the message.

Parameters
dateThe date header value.
size_type web::http::http_headers::size ( ) const
inline

Returns the number of header fields.

Returns
Number of header fields.

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