Logo
~Sockets~
~Examples~
~Contact~


HttpResponse Class Reference

#include <HttpResponse.h>

Inheritance diagram for HttpResponse:
Collaboration diagram for HttpResponse:

List of all members.


Public Member Functions

 HttpResponse (const std::string &version="HTTP/1.0")
 HttpResponse (const HttpResponse &src)
 ~HttpResponse ()
HttpResponseoperator= (const HttpResponse &src)
void SetHttpVersion (const std::string &value)
 HTTP/1.x.
const std::string & HttpVersion () const
void SetHttpStatusCode (int value)
int HttpStatusCode () const
void SetHttpStatusMsg (const std::string &value)
const std::string & HttpStatusMsg () const
void SetCookie (const std::string &value)
const std::string Cookie (const std::string &name) const
std::list< std::string > CookieNames () const
void Write (const std::string &str)
void Write (const char *buf, size_t sz)
void Writef (const char *format,...)
const IFileGetFile () const
void SetFile (const std::string &path)
 Replace memfile with file on disk, opened for read.
void Reset ()

Private Attributes

std::string m_http_version
int m_http_status_code
std::string m_http_status_msg
Utility::ncmap< std::string > m_cookie
std::auto_ptr< IFilem_file

Detailed Description

Definition at line 44 of file HttpResponse.h.


Constructor & Destructor Documentation

HttpResponse::HttpResponse ( const std::string &  version = "HTTP/1.0"  ) 

Definition at line 56 of file HttpResponse.cpp.

00056                                                    : HttpTransaction()
00057 , m_http_version( version )
00058 , m_http_status_code(0)
00059 , m_file( new MemFile )
00060 {
00061 }

HttpResponse::HttpResponse ( const HttpResponse src  ) 

Definition at line 65 of file HttpResponse.cpp.

00065                                                   : HttpTransaction(src)
00066 , m_http_version( src.m_http_version )
00067 , m_http_status_code( src.m_http_status_code )
00068 , m_http_status_msg( src.m_http_status_msg )
00069 , m_cookie( src.m_cookie )
00070 , m_file( src.m_file )
00071 {
00072 }

HttpResponse::~HttpResponse (  ) 

Definition at line 76 of file HttpResponse.cpp.

00077 {
00078 }


Member Function Documentation

HttpResponse & HttpResponse::operator= ( const HttpResponse src  ) 

Definition at line 82 of file HttpResponse.cpp.

References m_cookie, m_file, m_http_status_code, m_http_status_msg, and m_http_version.

00083 {
00084         m_http_version = src.m_http_version;
00085         m_http_status_code = src.m_http_status_code;
00086         m_http_status_msg = src.m_http_status_msg;
00087         m_cookie = src.m_cookie;
00088         m_file = src.m_file;
00089 
00090         HttpTransaction::operator=(src);
00091 
00092         return *this;
00093 }

void HttpResponse::SetHttpVersion ( const std::string &  value  ) 

HTTP/1.x.

Definition at line 97 of file HttpResponse.cpp.

References m_http_version.

00098 {
00099         m_http_version = value;
00100 }

const std::string & HttpResponse::HttpVersion (  )  const

Definition at line 104 of file HttpResponse.cpp.

References m_http_version.

Referenced by HttpBaseSocket::Respond().

00105 {
00106         return m_http_version;
00107 }

void HttpResponse::SetHttpStatusCode ( int  value  ) 

Definition at line 112 of file HttpResponse.cpp.

References m_http_status_code.

00113 {
00114         m_http_status_code = value;
00115 }

int HttpResponse::HttpStatusCode (  )  const

Definition at line 118 of file HttpResponse.cpp.

References m_http_status_code.

Referenced by HttpBaseSocket::Respond(), and Ajp13Socket::Respond().

00119 {
00120         return m_http_status_code;
00121 }

void HttpResponse::SetHttpStatusMsg ( const std::string &  value  ) 

Definition at line 126 of file HttpResponse.cpp.

References m_http_status_msg.

00127 {
00128         m_http_status_msg = value;
00129 }

const std::string & HttpResponse::HttpStatusMsg (  )  const

Definition at line 132 of file HttpResponse.cpp.

References m_http_status_msg.

Referenced by HttpBaseSocket::Respond(), and Ajp13Socket::Respond().

00133 {
00134         return m_http_status_msg;
00135 }

void HttpResponse::SetCookie ( const std::string &  value  ) 

Definition at line 139 of file HttpResponse.cpp.

References DEB, Parse::getword(), and m_cookie.

00140 {
00141         Parse pa(value, "=");
00142         std::string name = pa.getword();
00143         m_cookie[name] = value;
00144 DEB(fprintf(stderr, "HttpResponse::Set-Cookie<%s>: %s\n", name.c_str(), value.c_str());)
00145 }

const std::string HttpResponse::Cookie ( const std::string &  name  )  const

Definition at line 148 of file HttpResponse.cpp.

References DEB, and m_cookie.

Referenced by HttpBaseSocket::Respond(), and Ajp13Socket::Respond().

00149 {
00150         Utility::ncmap<std::string>::const_iterator it = m_cookie.find(name);
00151 DEB(fprintf(stderr, "HttpResponse; get value of Cookie<%s>: ", name.c_str());)
00152         if (it != m_cookie.end())
00153         {
00154 DEB(fprintf(stderr, "%s\n", it -> second.c_str());)
00155                 return it -> second;
00156         }
00157 DEB(fprintf(stderr, "\n");)
00158         return "";
00159 }

std::list< std::string > HttpResponse::CookieNames (  )  const

Definition at line 162 of file HttpResponse.cpp.

References DEB, and m_cookie.

Referenced by HttpBaseSocket::Respond(), and Ajp13Socket::Respond().

00163 {
00164         std::list<std::string> vec;
00165         DEB(fprintf(stderr, "HttpResponse::CookieNames; ");)
00166         for (Utility::ncmap<std::string>::const_iterator it = m_cookie.begin(); it != m_cookie.end(); it++)
00167         {
00168                 DEB(fprintf(stderr, " %s", it -> first.c_str());)
00169                 vec.push_back(it -> first);
00170         }
00171         DEB(fprintf(stderr, "\n");)
00172         return vec;
00173 }

void HttpResponse::Write ( const std::string &  str  ) 

Definition at line 178 of file HttpResponse.cpp.

00179 {
00180         Write( str.c_str(), str.size() );
00181 }

void HttpResponse::Write ( const char *  buf,
size_t  sz 
)

Definition at line 185 of file HttpResponse.cpp.

References m_file.

00186 {
00187         m_file -> fwrite( buf, 1, sz );
00188 }

void HttpResponse::Writef ( const char *  format,
  ... 
)

Definition at line 192 of file HttpResponse.cpp.

References m_file.

00193 {
00194         va_list ap;
00195         va_start(ap, format);
00196         char tmp[10000];
00197         vsprintf(tmp, format, ap);
00198         va_end(ap);
00199         m_file -> fwrite( tmp, 1, strlen(tmp) );
00200 }

const IFile& HttpResponse::GetFile (  )  const [inline]

void HttpResponse::SetFile ( const std::string &  path  ) 

Replace memfile with file on disk, opened for read.

Definition at line 204 of file HttpResponse.cpp.

References m_file.

00205 {
00206         m_file = std::auto_ptr<IFile>(new File);
00207         m_file -> fopen( path, "rb" );
00208 }

void HttpResponse::Reset (  )  [virtual]

Reimplemented from HttpTransaction.

Definition at line 212 of file HttpResponse.cpp.

References m_cookie, m_file, m_http_status_code, m_http_status_msg, m_http_version, and HttpTransaction::Reset().

00213 {
00214         HttpTransaction::Reset();
00215         m_http_version = "";
00216         m_http_status_code = 0;
00217         m_http_status_msg = "";
00218         while (!m_cookie.empty())
00219         {
00220                 m_cookie.erase(m_cookie.begin());
00221         }
00222         m_file = std::auto_ptr<IFile>(new MemFile);
00223 }


Member Data Documentation

std::string HttpResponse::m_http_version [private]

Definition at line 79 of file HttpResponse.h.

Referenced by HttpVersion(), operator=(), Reset(), and SetHttpVersion().

Definition at line 80 of file HttpResponse.h.

Referenced by HttpStatusCode(), operator=(), Reset(), and SetHttpStatusCode().

std::string HttpResponse::m_http_status_msg [private]

Definition at line 81 of file HttpResponse.h.

Referenced by HttpStatusMsg(), operator=(), Reset(), and SetHttpStatusMsg().

Utility::ncmap<std::string> HttpResponse::m_cookie [private]

Definition at line 82 of file HttpResponse.h.

Referenced by Cookie(), CookieNames(), operator=(), Reset(), and SetCookie().

std::auto_ptr<IFile> HttpResponse::m_file [mutable, private]

Definition at line 83 of file HttpResponse.h.

Referenced by operator=(), Reset(), SetFile(), Write(), and Writef().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4