/usr/share/doc/libpion-doc/html/http_2server_8hpp_source.html is in libpion-doc 5.0.4+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>pion: include/pion/http/server.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="files.html"><span>File List</span></a></li>
</ul>
</div>
<h1>include/pion/http/server.hpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// ---------------------------------------------------------------------</span>
<a name="l00002"></a>00002 <span class="comment">// pion: a Boost C++ framework for building lightweight HTTP interfaces</span>
<a name="l00003"></a>00003 <span class="comment">// ---------------------------------------------------------------------</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright (C) 2007-2012 Cloudmeter, Inc. (http://www.cloudmeter.com)</span>
<a name="l00005"></a>00005 <span class="comment">//</span>
<a name="l00006"></a>00006 <span class="comment">// Distributed under the Boost Software License, Version 1.0.</span>
<a name="l00007"></a>00007 <span class="comment">// See http://www.boost.org/LICENSE_1_0.txt</span>
<a name="l00008"></a>00008 <span class="comment">//</span>
<a name="l00009"></a>00009
<a name="l00010"></a>00010 <span class="preprocessor">#ifndef __PION_HTTP_SERVER_HEADER__</span>
<a name="l00011"></a>00011 <span class="preprocessor"></span><span class="preprocessor">#define __PION_HTTP_SERVER_HEADER__</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span>
<a name="l00013"></a>00013 <span class="preprocessor">#include <map></span>
<a name="l00014"></a>00014 <span class="preprocessor">#include <string></span>
<a name="l00015"></a>00015 <span class="preprocessor">#include <boost/asio.hpp></span>
<a name="l00016"></a>00016 <span class="preprocessor">#include <boost/function.hpp></span>
<a name="l00017"></a>00017 <span class="preprocessor">#include <boost/function/function2.hpp></span>
<a name="l00018"></a>00018 <span class="preprocessor">#include <boost/function/function3.hpp></span>
<a name="l00019"></a>00019 <span class="preprocessor">#include <boost/shared_ptr.hpp></span>
<a name="l00020"></a>00020 <span class="preprocessor">#include <boost/thread/mutex.hpp></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include <pion/config.hpp></span>
<a name="l00022"></a>00022 <span class="preprocessor">#include <pion/tcp/server.hpp></span>
<a name="l00023"></a>00023 <span class="preprocessor">#include <pion/tcp/connection.hpp></span>
<a name="l00024"></a>00024 <span class="preprocessor">#include <pion/http/request.hpp></span>
<a name="l00025"></a>00025 <span class="preprocessor">#include <pion/http/auth.hpp></span>
<a name="l00026"></a>00026 <span class="preprocessor">#include <pion/http/parser.hpp></span>
<a name="l00027"></a>00027
<a name="l00028"></a>00028
<a name="l00029"></a>00029 <span class="keyword">namespace </span>pion { <span class="comment">// begin namespace pion</span>
<a name="l00030"></a>00030 <span class="keyword">namespace </span>http { <span class="comment">// begin namespace http</span>
<a name="l00031"></a>00031
<a name="l00032"></a>00032
<a name="l00036"></a><a class="code" href="classpion_1_1http_1_1server.html">00036</a> <span class="keyword">class </span>PION_API <a class="code" href="classpion_1_1http_1_1server.html">server</a> :
<a name="l00037"></a>00037 <span class="keyword">public</span> tcp::<a class="code" href="classpion_1_1http_1_1server.html">server</a>
<a name="l00038"></a>00038 {
<a name="l00039"></a>00039
<a name="l00040"></a>00040 <span class="keyword">public</span>:
<a name="l00041"></a>00041
<a name="l00043"></a><a class="code" href="classpion_1_1http_1_1server.html#a74c41bc6ca8355497abb1401339a1306">00043</a> <span class="keyword">typedef</span> boost::function2<void, http::request_ptr&, tcp::connection_ptr&> request_handler_t;
<a name="l00044"></a>00044
<a name="l00046"></a>00046 <span class="keyword">typedef</span> boost::function3<void, http::request_ptr&, tcp::connection_ptr&,
<a name="l00047"></a><a class="code" href="classpion_1_1http_1_1server.html#a699708eee95801f47d59cb9f2279ab4b">00047</a> <span class="keyword">const</span> std::string&> error_handler_t;
<a name="l00048"></a>00048
<a name="l00049"></a>00049
<a name="l00051"></a><a class="code" href="classpion_1_1http_1_1server.html#a5632ccba73177582414d649c6316362d">00051</a> <span class="keyword">virtual</span> <a class="code" href="classpion_1_1http_1_1server.html#a5632ccba73177582414d649c6316362d" title="default destructor">~server</a>() { <span class="keywordflow">if</span> (is_listening()) stop(); }
<a name="l00052"></a>00052
<a name="l00058"></a><a class="code" href="classpion_1_1http_1_1server.html#a12ed7b808ae35c5e503f9d23d73860d7">00058</a> <span class="keyword">explicit</span> <a class="code" href="classpion_1_1http_1_1server.html">server</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> tcp_port = 0)
<a name="l00059"></a>00059 : tcp::<a class="code" href="classpion_1_1http_1_1server.html">server</a>(tcp_port),
<a name="l00060"></a>00060 m_bad_request_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_bad_request),
<a name="l00061"></a>00061 m_not_found_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_not_found_request),
<a name="l00062"></a>00062 m_server_error_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_server_error),
<a name="l00063"></a>00063 m_max_content_length(http::<a class="code" href="classpion_1_1http_1_1parser.html">parser</a>::DEFAULT_CONTENT_MAX)
<a name="l00064"></a>00064 {
<a name="l00065"></a>00065 set_logger(PION_GET_LOGGER(<span class="stringliteral">"pion.http.server"</span>));
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067
<a name="l00073"></a><a class="code" href="classpion_1_1http_1_1server.html#ac63e91762958da5d8122a1be80650382">00073</a> <span class="keyword">explicit</span> <a class="code" href="classpion_1_1http_1_1server.html">server</a>(<span class="keyword">const</span> boost::asio::ip::tcp::endpoint& endpoint)
<a name="l00074"></a>00074 : tcp::<a class="code" href="classpion_1_1http_1_1server.html">server</a>(endpoint),
<a name="l00075"></a>00075 m_bad_request_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_bad_request),
<a name="l00076"></a>00076 m_not_found_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_not_found_request),
<a name="l00077"></a>00077 m_server_error_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_server_error),
<a name="l00078"></a>00078 m_max_content_length(http::<a class="code" href="classpion_1_1http_1_1parser.html">parser</a>::DEFAULT_CONTENT_MAX)
<a name="l00079"></a>00079 {
<a name="l00080"></a>00080 set_logger(PION_GET_LOGGER(<span class="stringliteral">"pion.http.server"</span>));
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082
<a name="l00089"></a><a class="code" href="classpion_1_1http_1_1server.html#abdfcbc45db2b886e3bfcf0c6b867b0c2">00089</a> <span class="keyword">explicit</span> <a class="code" href="classpion_1_1http_1_1server.html">server</a>(<a class="code" href="classpion_1_1scheduler.html">scheduler</a>& sched, <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> tcp_port = 0)
<a name="l00090"></a>00090 : tcp::<a class="code" href="classpion_1_1http_1_1server.html">server</a>(sched, tcp_port),
<a name="l00091"></a>00091 m_bad_request_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_bad_request),
<a name="l00092"></a>00092 m_not_found_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_not_found_request),
<a name="l00093"></a>00093 m_server_error_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_server_error),
<a name="l00094"></a>00094 m_max_content_length(http::<a class="code" href="classpion_1_1http_1_1parser.html">parser</a>::DEFAULT_CONTENT_MAX)
<a name="l00095"></a>00095 {
<a name="l00096"></a>00096 set_logger(PION_GET_LOGGER(<span class="stringliteral">"pion.http.server"</span>));
<a name="l00097"></a>00097 }
<a name="l00098"></a>00098
<a name="l00105"></a><a class="code" href="classpion_1_1http_1_1server.html#ae84f4442d8bd468a1d77a1c96e29e681">00105</a> <a class="code" href="classpion_1_1http_1_1server.html">server</a>(<a class="code" href="classpion_1_1scheduler.html">scheduler</a>& sched, <span class="keyword">const</span> boost::asio::ip::tcp::endpoint& endpoint)
<a name="l00106"></a>00106 : tcp::<a class="code" href="classpion_1_1http_1_1server.html">server</a>(sched, endpoint),
<a name="l00107"></a>00107 m_bad_request_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_bad_request),
<a name="l00108"></a>00108 m_not_found_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_not_found_request),
<a name="l00109"></a>00109 m_server_error_handler(<a class="code" href="classpion_1_1http_1_1server.html">server</a>::handle_server_error),
<a name="l00110"></a>00110 m_max_content_length(http::<a class="code" href="classpion_1_1http_1_1parser.html">parser</a>::DEFAULT_CONTENT_MAX)
<a name="l00111"></a>00111 {
<a name="l00112"></a>00112 set_logger(PION_GET_LOGGER(<span class="stringliteral">"pion.http.server"</span>));
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114
<a name="l00121"></a>00121 <span class="keywordtype">void</span> add_resource(<span class="keyword">const</span> std::string& resource, request_handler_t request_handler);
<a name="l00122"></a>00122
<a name="l00128"></a>00128 <span class="keywordtype">void</span> remove_resource(<span class="keyword">const</span> std::string& resource);
<a name="l00129"></a>00129
<a name="l00136"></a>00136 <span class="keywordtype">void</span> add_redirect(<span class="keyword">const</span> std::string& requested_resource, <span class="keyword">const</span> std::string& new_resource);
<a name="l00137"></a>00137
<a name="l00139"></a><a class="code" href="classpion_1_1http_1_1server.html#ae519fa972938c911f02b0ec156615a0d">00139</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1http_1_1server.html#ae519fa972938c911f02b0ec156615a0d" title="sets the function that handles bad HTTP requests">set_bad_request_handler</a>(request_handler_t h) { m_bad_request_handler = h; }
<a name="l00140"></a>00140
<a name="l00142"></a><a class="code" href="classpion_1_1http_1_1server.html#a817a94e4117d2d8616c37b5f8d093e92">00142</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1http_1_1server.html#a817a94e4117d2d8616c37b5f8d093e92" title="sets the function that handles requests which match no other web services">set_not_found_handler</a>(request_handler_t h) { m_not_found_handler = h; }
<a name="l00143"></a>00143
<a name="l00145"></a><a class="code" href="classpion_1_1http_1_1server.html#ae88ab890a352b5bb389cbc8e6363e671">00145</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1http_1_1server.html#ae88ab890a352b5bb389cbc8e6363e671" title="sets the function that handles requests which match no other web services">set_error_handler</a>(error_handler_t h) { m_server_error_handler = h; }
<a name="l00146"></a>00146
<a name="l00148"></a><a class="code" href="classpion_1_1http_1_1server.html#af7e7f7b23f1d90d1e1e7171a33b29d7b">00148</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1http_1_1server.html#af7e7f7b23f1d90d1e1e7171a33b29d7b" title="clears the collection of resources recognized by the HTTP server">clear</a>(<span class="keywordtype">void</span>) {
<a name="l00149"></a>00149 <span class="keywordflow">if</span> (is_listening()) stop();
<a name="l00150"></a>00150 boost::mutex::scoped_lock resource_lock(m_resource_mutex);
<a name="l00151"></a>00151 m_resources.clear();
<a name="l00152"></a>00152 }
<a name="l00153"></a>00153
<a name="l00160"></a><a class="code" href="classpion_1_1http_1_1server.html#a375e54d0970e5d3dfc0eb50f902cf4c9">00160</a> <span class="keyword">static</span> <span class="keyword">inline</span> std::string <a class="code" href="classpion_1_1http_1_1server.html#a375e54d0970e5d3dfc0eb50f902cf4c9">strip_trailing_slash</a>(<span class="keyword">const</span> std::string& str) {
<a name="l00161"></a>00161 std::string result(str);
<a name="l00162"></a>00162 <span class="keywordflow">if</span> (!result.empty() && result[result.size()-1]==<span class="charliteral">'/'</span>)
<a name="l00163"></a>00163 result.resize(result.size() - 1);
<a name="l00164"></a>00164 <span class="keywordflow">return</span> result;
<a name="l00165"></a>00165 }
<a name="l00166"></a>00166
<a name="l00173"></a>00173 <span class="keyword">static</span> <span class="keywordtype">void</span> handle_bad_request(http::request_ptr& http_request_ptr,
<a name="l00174"></a>00174 tcp::connection_ptr& tcp_conn);
<a name="l00175"></a>00175
<a name="l00182"></a>00182 <span class="keyword">static</span> <span class="keywordtype">void</span> handle_not_found_request(http::request_ptr& http_request_ptr,
<a name="l00183"></a>00183 tcp::connection_ptr& tcp_conn);
<a name="l00184"></a>00184
<a name="l00192"></a>00192 <span class="keyword">static</span> <span class="keywordtype">void</span> handle_server_error(http::request_ptr& http_request_ptr,
<a name="l00193"></a>00193 tcp::connection_ptr& tcp_conn,
<a name="l00194"></a>00194 <span class="keyword">const</span> std::string& error_msg);
<a name="l00195"></a>00195
<a name="l00203"></a>00203 <span class="keyword">static</span> <span class="keywordtype">void</span> handle_forbidden_request(http::request_ptr& http_request_ptr,
<a name="l00204"></a>00204 tcp::connection_ptr& tcp_conn,
<a name="l00205"></a>00205 <span class="keyword">const</span> std::string& error_msg);
<a name="l00206"></a>00206
<a name="l00214"></a>00214 <span class="keyword">static</span> <span class="keywordtype">void</span> handle_method_not_allowed(http::request_ptr& http_request_ptr,
<a name="l00215"></a>00215 tcp::connection_ptr& tcp_conn,
<a name="l00216"></a>00216 <span class="keyword">const</span> std::string& allowed_methods = <span class="stringliteral">""</span>);
<a name="l00217"></a>00217
<a name="l00221"></a><a class="code" href="classpion_1_1http_1_1server.html#a5ccee5bdd4d7f59a348dd9475cba7ded">00221</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1http_1_1server.html#a5ccee5bdd4d7f59a348dd9475cba7ded">set_authentication</a>(http::auth_ptr <a class="code" href="classpion_1_1http_1_1auth.html">auth</a>) { m_auth_ptr = auth; }
<a name="l00222"></a>00222
<a name="l00224"></a><a class="code" href="classpion_1_1http_1_1server.html#acf80fa19484a66649c89cf9a23cc9251">00224</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1http_1_1server.html#acf80fa19484a66649c89cf9a23cc9251" title="sets the maximum length for HTTP request payload content">set_max_content_length</a>(std::size_t n) { m_max_content_length = n; }
<a name="l00225"></a>00225
<a name="l00226"></a>00226 <span class="keyword">protected</span>:
<a name="l00227"></a>00227
<a name="l00233"></a>00233 <span class="keyword">virtual</span> <span class="keywordtype">void</span> handle_connection(tcp::connection_ptr& tcp_conn);
<a name="l00234"></a>00234
<a name="l00242"></a>00242 <span class="keyword">virtual</span> <span class="keywordtype">void</span> handle_request(http::request_ptr& http_request_ptr,
<a name="l00243"></a>00243 tcp::connection_ptr& tcp_conn, <span class="keyword">const</span> boost::system::error_code& ec);
<a name="l00244"></a>00244
<a name="l00251"></a>00251 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> find_request_handler(<span class="keyword">const</span> std::string& resource,
<a name="l00252"></a>00252 request_handler_t& request_handler) <span class="keyword">const</span>;
<a name="l00253"></a>00253
<a name="l00254"></a>00254
<a name="l00255"></a>00255 <span class="keyword">private</span>:
<a name="l00256"></a>00256
<a name="l00258"></a>00258 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> MAX_REDIRECTS;
<a name="l00259"></a>00259
<a name="l00261"></a>00261 <span class="keyword">typedef</span> std::map<std::string, request_handler_t> resource_map_t;
<a name="l00262"></a>00262
<a name="l00264"></a>00264 <span class="keyword">typedef</span> std::map<std::string, std::string> redirect_map_t;
<a name="l00265"></a>00265
<a name="l00266"></a>00266
<a name="l00268"></a>00268 resource_map_t m_resources;
<a name="l00269"></a>00269
<a name="l00271"></a>00271 redirect_map_t m_redirects;
<a name="l00272"></a>00272
<a name="l00274"></a>00274 request_handler_t m_bad_request_handler;
<a name="l00275"></a>00275
<a name="l00277"></a>00277 request_handler_t m_not_found_handler;
<a name="l00278"></a>00278
<a name="l00280"></a>00280 error_handler_t m_server_error_handler;
<a name="l00281"></a>00281
<a name="l00283"></a>00283 <span class="keyword">mutable</span> boost::mutex m_resource_mutex;
<a name="l00284"></a>00284
<a name="l00286"></a>00286 http::auth_ptr m_auth_ptr;
<a name="l00287"></a>00287
<a name="l00289"></a>00289 std::size_t m_max_content_length;
<a name="l00290"></a>00290 };
<a name="l00291"></a>00291
<a name="l00292"></a>00292
<a name="l00294"></a>00294 <span class="keyword">typedef</span> boost::shared_ptr<server> server_ptr;
<a name="l00295"></a>00295
<a name="l00296"></a>00296
<a name="l00297"></a>00297 } <span class="comment">// end namespace http</span>
<a name="l00298"></a>00298 } <span class="comment">// end namespace pion</span>
<a name="l00299"></a>00299
<a name="l00300"></a>00300 <span class="preprocessor">#endif</span>
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on 16 Sep 2013 for pion by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>
|