⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 warsvrprotocolhttpheader.cpp

📁 ftpserver very good sample
💻 CPP
字号:
#include "StdAfx.h"#if WAR_RFC2068#include "WarSvrProtocolHttpHeader.h"   // class implemented#ifndef WAR_COLLECTOR_H#   include "WarCollector.h"#endif#ifndef WAR_LOG_H#   include "WarLog.h"#endifusing namespace std;/////////////////////////////// PUBLIC ///////////////////////////////////////const war_ccstr_t WarSvrProtocolHttpHeader::mMethodNames[HM_INVALID] = {    {"GET"},    {"OPTIONS"},    {"HEAD"},    {"POST"},    {"PUT"},    {"DELETE"},    {"TRACE"},};const war_ccstr_t WarSvrProtocolHttpHeader::mHttpVersionNames[HM_INVALID] = {    {"HTTP/1.1"},    {"HTTP/1.0"}};//============================= LIFECYCLE ====================================WarSvrProtocolHttpHeader::WarSvrProtocolHttpHeader(){    Reset();}// WarSvrProtocolHttpHeaderWarSvrProtocolHttpHeader::WarSvrProtocolHttpHeader(const WarSvrProtocolHttpHeader& from){}// WarSvrProtocolHttpHeaderWarSvrProtocolHttpHeader::~WarSvrProtocolHttpHeader(){}// ~WarSvrProtocolHttpHeader//============================= OPERATORS ====================================WarSvrProtocolHttpHeader& WarSvrProtocolHttpHeader::operator = (const WarSvrProtocolHttpHeader& from){    mHeaders = from.mHeaders;    return *this;}// =WarSvrProtocolHttpHeader& WarSvrProtocolHttpHeader::operator << (war_ccstr_t hdrStr)throw(WarException){    war_ccstr_t p = hdrStr;    p = ParseRequestLine(p);    while(p = ParseHdrLine(p))        ;    ParseUrl();    return *this;}//============================= OPERATIONS ===================================void WarSvrProtocolHttpHeader::Set(const std::string& name,         const std::string value)        throw (WarException){    mHeaders.insert(hdrpair_t(name, value));}void WarSvrProtocolHttpHeader::SetReplyCode(const HttpReplyCodeE& value){    mReturnValue = value;}void WarSvrProtocolHttpHeader::SetHttpVersion(const HttpVersionE& value){    switch(value)    {    case HTTP_1_0:        mHttpVersion = HTTP_1_0;        break;    default:        mHttpVersion = HTTP_1_1;        break;     }}void WarSvrProtocolHttpHeader::SetContentLength(const war_int64_t& length){    WarCollector<char> val;    val << length;    static const string name = "Content-Length";    Set(name, val.GetValue());}void WarSvrProtocolHttpHeader::Reset(){    mHttpVersion = HTTP_INVALID;    mReturnValue = HTTPR_INTERNAL_SERVER_ERROR;    mRequestMethod = HM_INVALID;    mRequestUri = "";    if (!mHeaders.empty())        mHeaders.erase(mHeaders.begin(), mHeaders.end());}void WarSvrProtocolHttpHeader::SetDefaultUrl(const WarUrl& newDefaultUrl){    mDefaultUrl = newDefaultUrl;}void WarSvrProtocolHttpHeader::VaildateHeaders(){    if (!IsSet("Date"))    {        WarTime now;        Set(string("Date"), now.FormatGMT("%a, %d %b %Y %H:%M:%S GMT"));    }    if (!IsSet("Server"))    {        string server = "WFDE/" WAR_VERSION;        Set(string("Server"), server);    }}//============================= CALLBACK   ===================================//============================= ACCESS     ===================================//============================= INQUIRY    ===================================war_ccstr_t WarSvrProtocolHttpHeader::GetVersionName() const{    switch(mHttpVersion)    {    case HTTP_1_0:        return "HTTP/1.0";    case HTTP_1_1:        return "HTTP/1.1";    default:        WarThrow(WarError(WAR_ERR_INVALID_CASE_VALUE), NULL);    }    return "ERROR"; // Compiler food}war_ccstr_t WarSvrProtocolHttpHeader::GetMethodName() const{    switch(GetMethod())    {    case HM_GET: return "GET";    case HM_OPTIONS: return "OPTIONS";    case HM_HEAD: return "HEAD";    case HM_POST: return "POST";    case HM_PUT: return "PUT";    case HM_DELETE: return "DELETE";    case HM_TRACE: return "TRACE";    default: return "INVALID";    }}war_ccstr_t WarSvrProtocolHttpHeader::GetResponseText() const{    war_ccstr_t rval = "";    switch(mReturnValue)    {    case  HTTPR_CONTINUE_100:        rval = "Continue";        break;    case HTTPR_SWITCHING_PROTOCOLS:        rval = "Switching protocols";        break;    case HTTPR_OK:        rval = "Ok";        break;    case HTTPR_CREATED:        rval = "Created";        break;    case HTTPR_ACCEPTED:        rval = "Accepted";        break;    case HTTPR_NON_AUTHORITATIVE_INFORMATION:        rval = "Non authorative information";        break;    case HTTPR_NO_CONTENT:        rval = "No content";        break;    case HTTPR_RESET_CONTENT:        rval = "Reset content";        break;    case HTTPR_PARTIAL_CONTENT:        rval = "Partial content";        break;    case HTTPR_MULTIPLE_CHOICES:        rval = "Multiple choises";        break;    case HTTPR_MOVED_PERMANENTLY:        rval = "Moved permanently";        break;    case HTTPR_MOVED_TEMPORARILY:        rval = "Moved temporarily";        break;    case HTTPR_SEE_OTHER:        rval = "See other";        break;    case HTTPR_NOT_MODIFIED:        rval = "Not modidied";        break;    case HTTPR_USE_PROXY:        rval = "Use proxy";        break;    case HTTPR_BAD_REQUEST:        rval = "Bad request";        break;    case HTTPR_UNAUTHORIZED:        rval = "Unauthorized";        break;    case HTTPR_PAYMENT_REQUIRED:        rval = "Payment required";        break;    case HTTPR_FORBIDDEN:        rval = "Forbidden";        break;    case HTTPR_NOT_FOUND:        rval = "Not found";        break;    case HTTPR_METHOD_NOT_ALLOWED:        rval = "Method not allowed";        break;    case HTTPR_NOT_ACCEPTABLE:        rval = "Not acceptable";        break;    case HTTPR_PROXY_AUTHENTICATION_REQUIRED:        rval = "Proxy authentication required";        break;    case HTTPR_REQUEST_TIME_OUT:        rval = "Request time out";        break;    case HTTPR_CONFLICT:        rval = "Conflict";        break;    case HTTPR_GONE:        rval = "Gone";        break;    case HTTPR_LENGTH_REQUIRED:        rval = "Length required";        break;    case HTTPR_PRECONDITION_FAILED:        rval = "Precondition failed";        break;    case HTTPR_REQUEST_ENTITY_TOO_LARGE:        rval = "Request entity too large";        break;    case HTTPR_REQUEST_URI_TOO_LARGE:        rval = "Request URI too large";        break;    case HTTPR_UNSUPPORTED_MEDIA_TYPE:        rval = "Unsupported media type";        break;    case HTTPR_INTERNAL_SERVER_ERROR:        rval = "Internal server error";        break;    case HTTPR_NOT_IMPLEMENTED:        rval = "Not implemented";        break;    case HTTPR_BAD_GATEWAY:        rval = "Bad gateway";        break;    case HTTPR_SERVICE_UNAVAILABLE:        rval = "Service unavailable";        break;    case HTTPR_GATEWAY_TIME_OUT:        rval = "Gateway time out";        break;    case HTTPR_HTTP_VERSION_NOT_SUPPORTED:        rval = "HTTP version not supported";        break;    default:        WarThrow(WarError(WAR_ERR_INVALID_CASE_VALUE), NULL);    }    return rval;}const std::string& WarSvrProtocolHttpHeader::GetHeaderValue(war_ccstr_t name) constthrow (WarException){    hdrmap_t::const_iterator P = mHeaders.find(string(name));    if (P == mHeaders.end())        WarThrow(WarError(WAR_ERR_OBJECT_NOT_FOUND), NULL);        return P->second;}bool WarSvrProtocolHttpHeader::IsSet(war_ccstr_t name) const{    hdrmap_t::const_iterator P = mHeaders.find(string(name));    return P != mHeaders.end();}/////////////////////////////// PROTECTED  ///////////////////////////////////war_ccstr_t WarSvrProtocolHttpHeader::ParseRequestLine(war_ccstr_t str) throw(WarException){    WarLog http_log(WARLOG_DEBUG, "WarSvrProtocolHttpHeader::ParseRequestLine()");    // RFC 2068 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -