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
IFileGetFile ()
void SetFile (const std::string &path)
 Replace memfile with file on disk, opened for read.
void SetFile (IFile *f)
 Replace memfile with another IFile.
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 46 of file HttpResponse.h.


Constructor & Destructor Documentation

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

Definition at line 57 of file HttpResponse.cpp.

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

HttpResponse::HttpResponse ( const HttpResponse src  ) 

Definition at line 66 of file HttpResponse.cpp.

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

HttpResponse::~HttpResponse (  ) 

Definition at line 77 of file HttpResponse.cpp.

00078 {
00079 }


Member Function Documentation

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

Definition at line 83 of file HttpResponse.cpp.

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

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

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

HTTP/1.x.

Definition at line 98 of file HttpResponse.cpp.

References m_http_version.

00099 {
00100         m_http_version = value;
00101 }

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

Definition at line 105 of file HttpResponse.cpp.

References m_http_version.

Referenced by HttpBaseSocket::IHttpServer_Respond().

00106 {
00107         return m_http_version;
00108 }

void HttpResponse::SetHttpStatusCode ( int  value  ) 

Definition at line 113 of file HttpResponse.cpp.

References m_http_status_code.

00114 {
00115         m_http_status_code = value;
00116 }

int HttpResponse::HttpStatusCode (  )  const

Definition at line 119 of file HttpResponse.cpp.

References m_http_status_code.

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

00120 {
00121         return m_http_status_code;
00122 }

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

Definition at line 127 of file HttpResponse.cpp.

References m_http_status_msg.

00128 {
00129         m_http_status_msg = value;
00130 }

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

Definition at line 133 of file HttpResponse.cpp.

References m_http_status_msg.

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

00134 {
00135         return m_http_status_msg;
00136 }

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

Definition at line 140 of file HttpResponse.cpp.

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

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

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

Definition at line 149 of file HttpResponse.cpp.

References DEB, and m_cookie.

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

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

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

Definition at line 163 of file HttpResponse.cpp.

References DEB, and m_cookie.

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

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

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

Definition at line 179 of file HttpResponse.cpp.

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

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

Definition at line 186 of file HttpResponse.cpp.

References m_file.

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

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

Definition at line 193 of file HttpResponse.cpp.

References m_file.

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

const IFile & HttpResponse::GetFile (  )  const

IFile & HttpResponse::GetFile (  ) 

Definition at line 212 of file HttpResponse.cpp.

References m_file.

00213 {
00214   return *m_file;
00215 }

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

Replace memfile with file on disk, opened for read.

Definition at line 219 of file HttpResponse.cpp.

References m_file.

00220 {
00221         m_file = std::auto_ptr<IFile>(new File);
00222         m_file -> fopen( path, "rb" );
00223 }

void HttpResponse::SetFile ( IFile f  ) 

Replace memfile with another IFile.

Definition at line 227 of file HttpResponse.cpp.

References m_file.

00228 {
00229         m_file = std::auto_ptr<IFile>(f);
00230 }

void HttpResponse::Reset (  )  [virtual]

Reimplemented from HttpTransaction.

Definition at line 234 of file HttpResponse.cpp.

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

Referenced by Ajp13Socket::Reset().

00235 {
00236         HttpTransaction::Reset();
00237         m_http_version = "";
00238         m_http_status_code = 0;
00239         m_http_status_msg = "";
00240         while (!m_cookie.empty())
00241         {
00242                 m_cookie.erase(m_cookie.begin());
00243         }
00244         m_file = std::auto_ptr<IFile>(new MemFile);
00245 }


Member Data Documentation

std::string HttpResponse::m_http_version [private]

Definition at line 84 of file HttpResponse.h.

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

Definition at line 85 of file HttpResponse.h.

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

std::string HttpResponse::m_http_status_msg [private]

Definition at line 86 of file HttpResponse.h.

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

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

Definition at line 87 of file HttpResponse.h.

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

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

Definition at line 88 of file HttpResponse.h.

Referenced by GetFile(), 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