Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Dv::Cgi::HttpHeader Class Reference

A class representing the header part of a HTTP response. More...

#include <httphead.h>

List of all members.

Public Types

typedef std::map< std::string,
std::string > 
header_map
 Type of data member that contains headers (except cookies).
typedef header_map::iterator iterator
 Iterator type that allows access to header strings (except cookies).
typedef header_map::const_iterator const_iterator
 Const Iterator type that allows access to header strings (except cookies).

Public Member Functions

 HttpHeader (const std::string &content="text/plain", bool debug=false)
 Constructor.
bool debug () const
const_iterator begin () const
const_iterator end () const
iterator begin ()
iterator end ()
size_t size () const
HttpHeadernocache ()
 Add header strings that prevent browser from caching the page.
HttpHeadercookie (const std::string &name, const std::string &value="", const std::string &path="/")
 Set cookie name = value for path.
HttpHeadercontent_type (const std::string &value)
 Add header strings to set content type.
HttpHeaderlocation (const std::string &value)
 Add header string to redirect browser to a given url.
HttpHeaderrefresh (size_t duration=0, const std::string &url="")
 Add header string to refresh browser.
HttpHeaderadd (const std::string &name, const std::string &value)
 General header add function.
HttpHeadererase (const std::string &name)
 Remove any header with a given name.
HttpHeaderclear ()
 Remove all header strings.

Private Types

typedef std::map< std::string,
std::pair< std::string, std::string > > 
cookie_map

Private Attributes

bool debug_
header_map headers_
cookie_map cookies_

Friends

std::ostream & operator<< (std::ostream &os, const HttpHeader &header)
 Output header strings and cookie definitions.


Detailed Description

A class representing the header part of a HTTP response.

The class makes it convenient to set up standard headers and cookies for the response:

Definition at line 27 of file httphead.h.


Member Typedef Documentation

typedef std::map<std::string,std::string> Dv::Cgi::HttpHeader::header_map
 

Type of data member that contains headers (except cookies).

Definition at line 35 of file httphead.h.

typedef header_map::iterator Dv::Cgi::HttpHeader::iterator
 

Iterator type that allows access to header strings (except cookies).

Definition at line 38 of file httphead.h.

typedef header_map::const_iterator Dv::Cgi::HttpHeader::const_iterator
 

Const Iterator type that allows access to header strings (except cookies).

Definition at line 41 of file httphead.h.

typedef std::map<std::string,std::pair<std::string,std::string> > Dv::Cgi::HttpHeader::cookie_map [private]
 

Definition at line 118 of file httphead.h.


Constructor & Destructor Documentation

Dv::Cgi::HttpHeader::HttpHeader const std::string &  content = "text/plain",
bool  debug = false
 

Constructor.

Parameters:
content type, default is "text/plain"
debug debug flag


Member Function Documentation

bool Dv::Cgi::HttpHeader::debug  )  const [inline]
 

Returns:
current debug status

Definition at line 44 of file httphead.h.

References debug_.

const_iterator Dv::Cgi::HttpHeader::begin  )  const [inline]
 

Returns:
const_iterator pointing to first header string

Definition at line 46 of file httphead.h.

References headers_.

const_iterator Dv::Cgi::HttpHeader::end  )  const [inline]
 

Returns:
const_iterator pointing past last header string

Definition at line 48 of file httphead.h.

References headers_.

iterator Dv::Cgi::HttpHeader::begin  )  [inline]
 

Returns:
iterator pointing to first header string

Definition at line 50 of file httphead.h.

References headers_.

iterator Dv::Cgi::HttpHeader::end  )  [inline]
 

Returns:
iterator pointing past last header string

Definition at line 52 of file httphead.h.

References headers_.

size_t Dv::Cgi::HttpHeader::size  )  const [inline]
 

Returns:
number of header strings, excluding cookies.

Definition at line 54 of file httphead.h.

References headers_.

HttpHeader& Dv::Cgi::HttpHeader::nocache  ) 
 

Add header strings that prevent browser from caching the page.

HttpHeader& Dv::Cgi::HttpHeader::cookie const std::string &  name,
const std::string &  value = "",
const std::string &  path = "/"
 

Set cookie name = value for path.

Providing an empty value will remove the cookie.

Parameters:
name of cookie
value of cookie (default is "", i.e. delete)
path of cookie (default is "/")
Returns:
reference to *this.

HttpHeader& Dv::Cgi::HttpHeader::content_type const std::string &  value  ) 
 

Add header strings to set content type.

Parameters:
value content type, e.g. "text/html"
Returns:
reference to *this.

HttpHeader& Dv::Cgi::HttpHeader::location const std::string &  value  ) 
 

Add header string to redirect browser to a given url.

Parameters:
value url to redirect to
Returns:
reference to *this.

HttpHeader& Dv::Cgi::HttpHeader::refresh size_t  duration = 0,
const std::string &  url = ""
 

Add header string to refresh browser.

Parameters:
duration in seconds that browser will wait before refresh, default is 0
url which will be accessed upon refresh, default is same url
Returns:
reference to *this.

HttpHeader& Dv::Cgi::HttpHeader::add const std::string &  name,
const std::string &  value
 

General header add function.

Parameters:
name first part of header line, e.g. "Content-type: ".
value rest of header line, e.g."text/html".
Returns:
reference to *this. Example
 httpheader.add("Content-type: ","text/html");
Warning:
Any previous value of "name" is replaced by the new value.

HttpHeader& Dv::Cgi::HttpHeader::erase const std::string &  name  ) 
 

Remove any header with a given name.

Parameters:
name first part of header to remove
Returns:
reference to *this.
See also:
Dv::Cgi::HttpHeader::add

HttpHeader& Dv::Cgi::HttpHeader::clear  )  [inline]
 

Remove all header strings.

Returns:
reference to *this.

Definition at line 107 of file httphead.h.

References headers_.


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &  os,
const HttpHeader header
[friend]
 

Output header strings and cookie definitions.

Parameters:
os to write headers to
header to write
Returns:
reference to os


Member Data Documentation

bool Dv::Cgi::HttpHeader::debug_ [private]
 

Definition at line 116 of file httphead.h.

Referenced by debug().

header_map Dv::Cgi::HttpHeader::headers_ [private]
 

Definition at line 117 of file httphead.h.

Referenced by begin(), clear(), end(), and size().

cookie_map Dv::Cgi::HttpHeader::cookies_ [private]
 

Definition at line 119 of file httphead.h.


The documentation for this class was generated from the following file:
dvcgi-0.5.14 [22 January, 2006]