fastdo  0.6.8
http::Header类 参考

代表HTTP头部 更多...

#include <http_misc.hpp>

class  ContentDisposition
 Content-Disposition域 更多...
 
class  ContentType
 Content-Type域 更多...
 
class  HeaderField
 解析/描述头域字段的值 更多...
 

Public 成员函数

 Header ()
 构造函数0 更多...
 
 Header (std::initializer_list< std::pair< winux::String, winux::Mixed > > list)
 构造函数1 更多...
 
void clear ()
 清空 更多...
 
winux::String toString (bool isAddCrlfAtEnd=true) const
 转为字符串,isAddCrlfAtEnd指示末尾是否添加\r\n 更多...
 
Headerparse (winux::String const &headerStr)
 从"HeaderField: XXXXX"字符串解析头部,可重复调用,不会清空先前解析的结果,要清空请调用clear() 更多...
 
winux::String const & operator[] (winux::String const &name) const
 
winux::Stringoperator[] (winux::String const &name)
 
winux::StringArray getHeaders (winux::String const &name) const
 取得所有指定name的field值 更多...
 
winux::String getHeader (winux::String const &name, winux::String const &defval=winux::String()) const
 
template<typename _Ty >
_Ty getHeader (winux::String const &name, _Ty const &defval=_Ty()) const
 
void addHeader (winux::String const &name, winux::String const &value)
 添加头 更多...
 
void setHeader (winux::String const &name, winux::String const &value)
 
bool hasHeader (winux::String const &name) const
 
void delHeader (winux::String const &name)
 
template<typename _HeaderField >
bool get (winux::String const &name, _HeaderField *field) const
 
template<typename _HeaderField >
_HeaderField get (winux::String const &name) const
 
winux::StringWriter operator() (winux::String const &name)
 设置headers,可以增加新头域 更多...
 
winux::StringWriter operator() (winux::String const &name, int i)
 修改multiheaders,无法增加新头域 更多...
 
winux::String getMultiHeader (winux::String const &name, int i, winux::String const &defval=winux::String()) const
 
void addMultiHeader (winux::String const &name, winux::String const &value)
 
bool hasMultiHeader (winux::String const &name) const
 
void delMultiHeader (int index)
 
void setResponseLine (winux::String const &responseLine, bool setStatus=true)
 设置响应行 格式: HttpVersion StatusCode StatusStr
eg. HTTP/1.1 200 OK 更多...
 
void setRequestLine (winux::String const &requestLine)
 设置请求行 格式: Method URL HttpVersion
eg. GET /index.do HTTP/1.1 更多...
 
winux::String getStatusLine (bool isAddCrlf=false) const
 取得状态行,isAddCrlf指示末尾是否添加‘回车换行’,默认不添加 更多...
 
winux::String const & getMethod () const
 方法. For a request: required. 更多...
 
winux::String const & getUrl () const
 URL. For a request: required. 更多...
 
winux::String const & getStatusCode () const
 状态码. For a response: required. 更多...
 
winux::String const & getStatusStr () const
 状态文本. For a response: Not required 更多...
 
winux::String const & getVersion () const
 HTTP版本. 更多...
 
HeadersetMethod (winux::String const &method)
 方法. For a request: required. 更多...
 
HeadersetUrl (winux::String const &url)
 URL. For a request: required. 更多...
 
HeadersetStatusCode (winux::String const &statusCode)
 状态码. For a response: required. 更多...
 
HeadersetStatusStr (winux::String const &statusStr)
 状态文本. For a response: Not required 更多...
 
HeadersetVersion (winux::String const &version)
 HTTP版本. 更多...
 
bool enumHeader (winux::String *name, winux::String *value) const
 枚举所有头域一遍,多次调用即可,当完成枚举后返回false。再次调用即可重新枚举。 更多...
 

详细描述

代表HTTP头部

有两种头域:只能出现一次的域存在headers中,能出现多次的域存在multiHeaders中。提供了两套方法分别操作它们。

在文件 http_misc.hpp10 行定义.

构造及析构函数说明

http::Header::Header ( )

构造函数0

http::Header::Header ( std::initializer_list< std::pair< winux::String, winux::Mixed > >  list)

构造函数1

成员函数说明

void http::Header::addHeader ( winux::String const &  name,
winux::String const &  value 
)

添加头

如果name已经在multiHeaders出现,则说明是multiheader,新值直接加入multiHeaders.
如果name已经在header出现,则说明是multiheader,之前值移入multiHeaders并从headers中移除,新值直接加入multiHeaders.
否则加入headers.

void http::Header::addMultiHeader ( winux::String const &  name,
winux::String const &  value 
)
void http::Header::clear ( )

清空

void http::Header::delHeader ( winux::String const &  name)
inline

在文件 http_misc.hpp92 行定义.

void http::Header::delMultiHeader ( int  index)
bool http::Header::enumHeader ( winux::String name,
winux::String value 
) const

枚举所有头域一遍,多次调用即可,当完成枚举后返回false。再次调用即可重新枚举。

template<typename _HeaderField >
bool http::Header::get ( winux::String const &  name,
_HeaderField *  field 
) const
inline

在文件 http_misc.hpp95 行定义.

template<typename _HeaderField >
_HeaderField http::Header::get ( winux::String const &  name) const
inline

在文件 http_misc.hpp105 行定义.

winux::String http::Header::getHeader ( winux::String const &  name,
winux::String const &  defval = winux::String() 
) const
inline

在文件 http_misc.hpp82 行定义.

template<typename _Ty >
_Ty http::Header::getHeader ( winux::String const &  name,
_Ty const &  defval = _Ty() 
) const
inline

在文件 http_misc.hpp83 行定义.

winux::StringArray http::Header::getHeaders ( winux::String const &  name) const

取得所有指定name的field值

winux::String const& http::Header::getMethod ( ) const
inline

方法. For a request: required.

在文件 http_misc.hpp137 行定义.

winux::String http::Header::getMultiHeader ( winux::String const &  name,
int  i,
winux::String const &  defval = winux::String() 
) const
winux::String const& http::Header::getStatusCode ( ) const
inline

状态码. For a response: required.

在文件 http_misc.hpp141 行定义.

winux::String http::Header::getStatusLine ( bool  isAddCrlf = false) const

取得状态行,isAddCrlf指示末尾是否添加‘回车换行’,默认不添加

winux::String const& http::Header::getStatusStr ( ) const
inline

状态文本. For a response: Not required

在文件 http_misc.hpp143 行定义.

winux::String const& http::Header::getUrl ( ) const
inline

URL. For a request: required.

在文件 http_misc.hpp139 行定义.

winux::String const& http::Header::getVersion ( ) const
inline

HTTP版本.

For a request: Not required. For a response: required.

在文件 http_misc.hpp148 行定义.

bool http::Header::hasHeader ( winux::String const &  name) const
inline

在文件 http_misc.hpp91 行定义.

bool http::Header::hasMultiHeader ( winux::String const &  name) const
winux::StringWriter http::Header::operator() ( winux::String const &  name)

设置headers,可以增加新头域

winux::StringWriter http::Header::operator() ( winux::String const &  name,
int  i 
)

修改multiheaders,无法增加新头域

参数
i指定是第几个,base on 0
winux::String const& http::Header::operator[] ( winux::String const &  name) const
winux::String& http::Header::operator[] ( winux::String const &  name)
Header& http::Header::parse ( winux::String const &  headerStr)

从"HeaderField: XXXXX"字符串解析头部,可重复调用,不会清空先前解析的结果,要清空请调用clear()

void http::Header::setHeader ( winux::String const &  name,
winux::String const &  value 
)
inline

在文件 http_misc.hpp90 行定义.

Header& http::Header::setMethod ( winux::String const &  method)
inline

方法. For a request: required.

在文件 http_misc.hpp151 行定义.

void http::Header::setRequestLine ( winux::String const &  requestLine)

设置请求行 格式: Method URL HttpVersion
eg. GET /index.do HTTP/1.1

void http::Header::setResponseLine ( winux::String const &  responseLine,
bool  setStatus = true 
)

设置响应行 格式: HttpVersion StatusCode StatusStr
eg. HTTP/1.1 200 OK

参数
setStatus指示是否同时设置"Status:"头域,FCGI程序必须用Status修改响应状态码
Header& http::Header::setStatusCode ( winux::String const &  statusCode)
inline

状态码. For a response: required.

在文件 http_misc.hpp155 行定义.

Header& http::Header::setStatusStr ( winux::String const &  statusStr)
inline

状态文本. For a response: Not required

在文件 http_misc.hpp157 行定义.

Header& http::Header::setUrl ( winux::String const &  url)
inline

URL. For a request: required.

在文件 http_misc.hpp153 行定义.

Header& http::Header::setVersion ( winux::String const &  version)
inline

HTTP版本.

For a request: Not required. For a response: required.

在文件 http_misc.hpp162 行定义.

winux::String http::Header::toString ( bool  isAddCrlfAtEnd = true) const

转为字符串,isAddCrlfAtEnd指示末尾是否添加\r\n


该类的文档由以下文件生成: