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

📄 _h_t_t_p_request_8hpp-source.html

📁 用c++编写http server的源码库,对socket等网络处理的代码可迅速转为己用.
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<a name="l00115"></a>00115     <a name="l00117"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#ac7d927b4f3f0041f278a3ea43e4708e">00117</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_request.html#ac7d927b4f3f0041f278a3ea43e4708e" title="sets the resource or uri-stem requested">setResource</a>(<span class="keyword">const</span> std::string&amp; str) { m_resource = str; }<a name="l00118"></a>00118     <a name="l00120"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#30eb2a25bee0aa302e741d6f28d2c5d7">00120</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_request.html#30eb2a25bee0aa302e741d6f28d2c5d7" title="sets the uri-query or query string requested">setQueryString</a>(<span class="keyword">const</span> std::string&amp; str) { m_query_string = str; }<a name="l00121"></a>00121     <a name="l00123"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#5c5f7e7d15adf7e89ab876bff6ae13ba">00123</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_request.html#5c5f7e7d15adf7e89ab876bff6ae13ba" title="sets the request's major HTTP version number">setVersionMajor</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n) { m_version_major = n; }<a name="l00124"></a>00124 <a name="l00126"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#82cef1243dc60730885862234c4ff8d5">00126</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_request.html#82cef1243dc60730885862234c4ff8d5" title="sets the request's minor HTTP version number">setVersionMinor</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n) { m_version_minor = n; }<a name="l00127"></a>00127 <a name="l00129"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#0b98f0cb5f7baedd16336e3910b24e99">00129</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_request.html#0b98f0cb5f7baedd16336e3910b24e99" title="sets the length of the POST content (in bytes)">setContentLength</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> n) { m_content_length = n; }<a name="l00130"></a>00130     <a name="l00133"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#43f248f347da567673b3b9dcb73987d9">00133</a>     <span class="keyword">inline</span> <span class="keywordtype">char</span> *<a class="code" href="classpion_1_1_h_t_t_p_request.html#43f248f347da567673b3b9dcb73987d9">createPostContentBuffer</a>(<span class="keywordtype">void</span>) {<a name="l00134"></a>00134         m_post_content.reset(<span class="keyword">new</span> <span class="keywordtype">char</span>[m_content_length]);<a name="l00135"></a>00135         <span class="keywordflow">return</span> m_post_content.get();<a name="l00136"></a>00136     }<a name="l00137"></a>00137     <a name="l00139"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#63e028609f74b47b51b3574ed02074fe">00139</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_request.html#63e028609f74b47b51b3574ed02074fe" title="adds a value for the HTTP request header key">addHeader</a>(<span class="keyword">const</span> std::string&amp; key, <span class="keyword">const</span> std::string&amp; value) {<a name="l00140"></a>00140         m_headers.insert(std::make_pair(key, value));<a name="l00141"></a>00141     }<a name="l00142"></a>00142     <a name="l00144"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#c601e624bd3e7c0ec0c1fff015bc4ab5">00144</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_request.html#c601e624bd3e7c0ec0c1fff015bc4ab5" title="adds a value for the query key">addQuery</a>(<span class="keyword">const</span> std::string&amp; key, <span class="keyword">const</span> std::string&amp; value) {<a name="l00145"></a>00145         m_query_params.insert(std::make_pair(key, value));<a name="l00146"></a>00146     }<a name="l00147"></a>00147     <a name="l00150"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#fafad43f3c39689eb5dbe39217304a2e">00150</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_request.html#fafad43f3c39689eb5dbe39217304a2e">addCookie</a>(<span class="keyword">const</span> std::string&amp; key, <span class="keyword">const</span> std::string&amp; value) {<a name="l00151"></a>00151         m_cookie_params.insert(std::make_pair(key, value));<a name="l00152"></a>00152     }<a name="l00153"></a>00153 <a name="l00155"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#c84845e80724c972eb0cf01b2ca85b10">00155</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_request.html#c84845e80724c972eb0cf01b2ca85b10" title="sets whether or not the request is valid">setIsValid</a>(<span class="keywordtype">bool</span> b = <span class="keyword">true</span>) { m_is_valid = b; }<a name="l00156"></a>00156     <a name="l00158"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#4ba13ad759e2c087e6892140fae74622">00158</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1_h_t_t_p_request.html#4ba13ad759e2c087e6892140fae74622" title="clears all request data">clear</a>(<span class="keywordtype">void</span>) {<a name="l00159"></a>00159         m_resource.erase();<a name="l00160"></a>00160         m_query_string.erase();<a name="l00161"></a>00161         m_method.erase();<a name="l00162"></a>00162         m_version_major = m_version_minor = 0;<a name="l00163"></a>00163         m_content_length = 0;<a name="l00164"></a>00164         m_post_content.reset();<a name="l00165"></a>00165         m_headers.clear();<a name="l00166"></a>00166         m_query_params.clear();<a name="l00167"></a>00167         m_cookie_params.clear();<a name="l00168"></a>00168     }<a name="l00169"></a>00169 <a name="l00171"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#85253674700ca08346f842aec51d75f2">00171</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classpion_1_1_h_t_t_p_request.html#85253674700ca08346f842aec51d75f2" title="returns true if the HTTP connection may be kept alive">checkKeepAlive</a>(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{<a name="l00172"></a>00172         <span class="keywordflow">return</span> (<a class="code" href="classpion_1_1_h_t_t_p_request.html#fed7a4e767c2d5a087ae505532930bf0" title="returns a value for the header if any are defined; otherwise, an empty string">getHeader</a>(<a class="code" href="structpion_1_1_h_t_t_p_types.html#2da8e7f4b605c4049dfd6ad5a44a98fe">HTTPTypes::HEADER_CONNECTION</a>) != <span class="stringliteral">"close"</span><a name="l00173"></a>00173                 &amp;&amp; (<a class="code" href="classpion_1_1_h_t_t_p_request.html#b25a2cba3f009d101e0d0104e5d5c2ab" title="returns the request's major HTTP version number">getVersionMajor</a>() &gt; 1<a name="l00174"></a>00174                     || (<a class="code" href="classpion_1_1_h_t_t_p_request.html#b25a2cba3f009d101e0d0104e5d5c2ab" title="returns the request's major HTTP version number">getVersionMajor</a>() &gt;= 1 &amp;&amp; <a class="code" href="classpion_1_1_h_t_t_p_request.html#ff4ce1dcd203aeb6ff30332aac309583" title="returns the request's minor HTTP version number">getVersionMinor</a>() &gt;= 1)) );<a name="l00175"></a>00175     }   <a name="l00176"></a>00176     <a name="l00177"></a>00177     <a name="l00178"></a>00178 <span class="keyword">protected</span>:<a name="l00179"></a>00179     <a name="l00181"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#2bf9d44a45725029975a00e365ea2e34">00181</a>     <a class="code" href="classpion_1_1_h_t_t_p_request.html#2bf9d44a45725029975a00e365ea2e34" title="protected constructor restricts creation of objects (use create())">HTTPRequest</a>(<span class="keywordtype">void</span>)<a name="l00182"></a>00182         : m_version_major(0), m_version_minor(0),<a name="l00183"></a>00183         m_content_length(0), m_is_valid(false)<a name="l00184"></a>00184     {}<a name="l00185"></a>00185 <a name="l00194"></a><a class="code" href="classpion_1_1_h_t_t_p_request.html#3a204b37ac0fba5b30c0ee3e1d2d1170">00194</a>     <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keyword">const</span> std::string&amp; <a class="code" href="classpion_1_1_h_t_t_p_request.html#3a204b37ac0fba5b30c0ee3e1d2d1170">getValue</a>(<span class="keyword">const</span> <a class="code" href="structpion_1_1_h_t_t_p_types.html#c860abe7b994d3c0311318f2e335086e" title="data type for a dictionary of strings (used for HTTP headers)">HTTPTypes::StringDictionary</a>&amp; dict,<a name="l00195"></a>00195                                        <span class="keyword">const</span> std::string&amp; key)<a name="l00196"></a>00196     {<a name="l00197"></a>00197         HTTPTypes::StringDictionary::const_iterator i = dict.find(key);<a name="l00198"></a>00198         <span class="keywordflow">return</span> ( (i==dict.end()) ? <a class="code" href="structpion_1_1_h_t_t_p_types.html#0e0740339b279094944014296a487a4e">HTTPTypes::STRING_EMPTY</a> : i-&gt;second );<a name="l00199"></a>00199     }<a name="l00200"></a>00200 <a name="l00201"></a>00201     <a name="l00202"></a>00202 <span class="keyword">private</span>:<a name="l00203"></a>00203     <a name="l00205"></a>00205     std::string                     m_method;<a name="l00206"></a>00206 <a name="l00208"></a>00208     std::string                     m_resource;<a name="l00209"></a>00209     <a name="l00211"></a>00211     std::string                     m_query_string;<a name="l00212"></a>00212     <a name="l00214"></a>00214     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>                    m_version_major;<a name="l00215"></a>00215 <a name="l00217"></a>00217     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>                    m_version_minor;<a name="l00218"></a>00218     <a name="l00220"></a>00220     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>                   m_content_length;<a name="l00221"></a>00221 <a name="l00223"></a>00223     boost::scoped_array&lt;char&gt;       m_post_content;<a name="l00224"></a>00224     <a name="l00226"></a>00226     <a class="code" href="structpion_1_1_h_t_t_p_types.html#04764395d3025e0c796c4b328e886d03" title="data type for HTTP headers">HTTPTypes::Headers</a>              m_headers;<a name="l00227"></a>00227 <a name="l00229"></a>00229     <a class="code" href="structpion_1_1_h_t_t_p_types.html#76461bc9a17ce90abb016c3a5b7d7bee" title="data type for HTTP query parameters">HTTPTypes::QueryParams</a>          m_query_params;<a name="l00230"></a>00230 <a name="l00232"></a>00232     <a class="code" href="structpion_1_1_h_t_t_p_types.html#ce1e6366bc601e16a0a10d61f5d690f9" title="data type for HTTP cookie parameters">HTTPTypes::CookieParams</a>         m_cookie_params;<a name="l00233"></a>00233     <a name="l00235"></a>00235     <span class="keywordtype">bool</span>                            m_is_valid;<a name="l00236"></a>00236 };<a name="l00237"></a>00237 <a name="l00238"></a>00238 <a name="l00240"></a><a class="code" href="namespacepion.html#3c0f3fad0f449ebd309eaf4872f2b222">00240</a> <span class="keyword">typedef</span> boost::shared_ptr&lt;HTTPRequest&gt;      <a class="code" href="namespacepion.html#3c0f3fad0f449ebd309eaf4872f2b222" title="data type for a HTTP request pointer">HTTPRequestPtr</a>;<a name="l00241"></a>00241 <a name="l00242"></a>00242 <a name="l00243"></a>00243 }   <span class="comment">// end namespace pion</span><a name="l00244"></a>00244 <a name="l00245"></a>00245 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Tue Jun 19 13:29:22 2007 for libpion by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.2 </small></address></body></html>

⌨️ 快捷键说明

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