📄 httprequest.h
字号:
#if !defined(HttpRequest_H)
#define HttpRequest_H
#include "HttpBuffer.h"
#include "TimeStamp.h"
#include <deque>
#include <map>
#include <string>
#include <sstream>
using namespace std;
#pragma warning( disable:4172 )
enum
{
idAppNoExecute = 0x0000,
idAppExecute = 0x0001,
idAppCgi = 0x0002,
idAppIsapi = 0x0004
};
//##ModelId=424BB6440324
enum REQSTATUS
{
//##ModelId=424BB6440326
REQ_REQUEST=0,
//##ModelId=424BB6440334
REQ_HEADER,
//##ModelId=424BB6440343
REQ_BODY,
//##ModelId=424BB6440344
REQ_SIMPLE,
//##ModelId=424BB6440353
REQ_DONE
};
/////////////////////////////////////////////////////////////////////////////////////
// HttpRequest
//
// Purpose: represent an http request
//##ModelId=424BB6440354
typedef map<string,string> StringMap;
//##ModelId=424BB6440364
typedef StringMap::iterator itrStringMap;
//##ModelId=424BB6440373
typedef StringMap::reverse_iterator revItrStringMap;
//##ModelId=424BB64403C0
class HttpRequest :
public HttpBuffer
{
public:
//////////////////////////////////////////////////////////
// http request format
//
// Request Line Required
// General Header Optional
// Request Header Optional
// Entity Header Optional
// Entity Body Optional
//##ModelId=424BB64403C3
string _url; // url for request
//##ModelId=424BB64403D1
string _path; // full path for request
//##ModelId=424BB64403E1
string _pathInfo; // path information
//##ModelId=424BB64403E6
string _pathTranslated; // path translated
//##ModelId=424BB6450008
string _method; // request method
//##ModelId=424BB6450018
string _args; // args for request
//##ModelId=424BB6450028
string _host; // host for request
//##ModelId=424BB645002D
string _version; // http version
//##ModelId=424BB6450036
long _execute; // shows if execute app
//##ModelId=424BB6450046
long _status; // shows status of request
//##ModelId=424BB6450047
long _attributes; // request attributes
//##ModelId=424BB6450055
long _processState; // request processing state
//##ModelId=424BB6450066
StringMap _headers; // param-value pairs
//##ModelId=424BB6450075
long _length; // lenght of request
public:
//##ModelId=424BB6450084
HttpRequest ( string & version = string("1.0") );
//##ModelId=424BB6450086
virtual ~HttpRequest ();
// create/release
//##ModelId=424BB6450088
bool create ();
//##ModelId=424BB6450094
bool create ( long request, string & file = string("") );
//##ModelId=424BB64500A4
void release ();
// get/set state
//##ModelId=424BB64500A5
void setState ( HttpRequest & request )
{
*this = request;
}
//##ModelId=424BB64500B3
void getState ( HttpRequest & request )
{
request = *this;
}
// operators
//##ModelId=424BB64500B5
void operator = ( const HttpRequest & request );
// access methods
//##ModelId=424BB64500C4
string & getUrl ()
{
return _url;
}
//##ModelId=424BB64500C5
void setUrl ( string & set )
{
_url = set;
}
//##ModelId=424BB64500D3
string & getFullPath ()
{
return _path;
}
//##ModelId=424BB64500D4
void setFullPath ( string & set )
{
_path = set;
}
//##ModelId=424BB64500E3
string & getPathInfo ()
{
return _pathInfo;
}
//##ModelId=424BB64500E4
void setPathInfo ( string & set )
{
_pathInfo = set;
}
//##ModelId=424BB64500F3
string & getPathTranslated ()
{
return _pathTranslated;
}
//##ModelId=424BB64500F4
void setPathTranslated ( string & set )
{
_pathTranslated = set;
}
//##ModelId=424BB6450101
string & getMethod ()
{
return _method;
}
//##ModelId=424BB6450102
void setMethod ( string & set )
{
_method = set;
}
//##ModelId=424BB6450111
string & getVersion ()
{
return _version;
}
//##ModelId=424BB6450112
void setVersion ( string & set )
{
set = _version;
}
//##ModelId=424BB6450121
long getExecute ()
{
return _execute;
}
//##ModelId=424BB6450122
void setExecute ( long set )
{
_execute = set;
}
//##ModelId=424BB6450130
long getStatus ()
{
return _status;
}
//##ModelId=424BB6450131
void setStatus ( long set )
{
_status = set;
}
//##ModelId=424BB6450140
long getAttributes ()
{
return _attributes;
}
//##ModelId=424BB6450141
void setAttributes ( long set )
{
_attributes = set;
}
//##ModelId=424BB645014F
long getProcessState ()
{
return _processState;
}
//##ModelId=424BB6450150
void setProcessState ( long set )
{
_processState = set;
}
//##ModelId=424BB645015F
string & getArgs ()
{
return _args;
}
//##ModelId=424BB6450160
void setArgs ( string & set )
{
_args = set;
}
//##ModelId=424BB6450162
string & getHost ()
{
return _host;
}
//##ModelId=424BB645016F
void setHost ( string & set )
{
_host = set;
}
//##ModelId=424BB6450171
long getLength ()
{
return _length;
}
//##ModelId=424BB645017E
void setLength ( long set )
{
_length = set;
}
//##ModelId=424BB6450180
bool addHeaderValue ( LPTSTR param, string & value )
{
if ( !param == 0 || strlen(param) == 0 || value.empty() )
return false;
// add value
_headers[ string(param)] = value;
return true;
}
//##ModelId=424BB645019E
bool addHeaderValue ( string & param, string & value )
{
if ( param.empty() == 0 || value.empty() )
return false;
// add value
_headers[param] = value;
return true;
}
//##ModelId=424BB64501BD
string getHeaderValue ( string & param )
{
// if find value return it
itrStringMap itr = _headers.find(param);
if ( itr != _headers.end() )
return (*itr).second;
else
return string("");
}
//##ModelId=424BB64501CD
string getHeaderValue ( LPTSTR param )
{
// if find value return it
itrStringMap itr = _headers.find(string(param));
if ( itr != _headers.end() )
return (*itr).second;
else
return string("");
}
// add status
//##ModelId=424BB64501DD
int addStatus( long status )
{
// save the status for this request
setStatus(status);
// store status in buffer
return HttpBuffer::addStatus( status );
}
};
/////////////////////////////////////////////////////////////////////////////////////
// HttpRequestList
//
// Purpose: list of http requests
//##ModelId=424BB64501FB
class HttpRequestList :
public deque<HttpRequest>
{
public:
//##ModelId=424BB645021D
HttpRequestList ()
{}
//##ModelId=424BB645021E
virtual ~HttpRequestList ()
{
clear();
}
};
//##ModelId=424BB645022A
typedef deque<HttpRequest>::iterator itrHttpRequest;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -