This file is indexed.

/usr/share/doc/libpion-doc/html/request__writer_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
<!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/request_writer.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&nbsp;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&nbsp;List</span></a></li>
    </ul>
  </div>
<h1>include/pion/http/request_writer.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_REQUEST_WRITER_HEADER__</span>
<a name="l00011"></a>00011 <span class="preprocessor"></span><span class="preprocessor">#define __PION_HTTP_REQUEST_WRITER_HEADER__</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;boost/asio.hpp&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;boost/bind.hpp&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;boost/noncopyable.hpp&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;boost/shared_ptr.hpp&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;boost/enable_shared_from_this.hpp&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;pion/config.hpp&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;pion/http/writer.hpp&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;pion/http/request.hpp&gt;</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="keyword">namespace </span>pion {    <span class="comment">// begin namespace pion</span>
<a name="l00024"></a>00024 <span class="keyword">namespace </span>http {    <span class="comment">// begin namespace http</span>
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 
<a name="l00030"></a><a class="code" href="classpion_1_1http_1_1request__writer.html">00030</a> <span class="keyword">class </span><a class="code" href="classpion_1_1http_1_1request__writer.html">request_writer</a> :
<a name="l00031"></a>00031     <span class="keyword">public</span> http::<a class="code" href="classpion_1_1http_1_1writer.html">writer</a>,
<a name="l00032"></a>00032     <span class="keyword">public</span> boost::enable_shared_from_this&lt;request_writer&gt;
<a name="l00033"></a>00033 {
<a name="l00034"></a>00034 <span class="keyword">public</span>:
<a name="l00035"></a>00035     
<a name="l00037"></a><a class="code" href="classpion_1_1http_1_1request__writer.html#a4e864e362bfa9d132175f80503b32782">00037</a>     <span class="keyword">virtual</span> <a class="code" href="classpion_1_1http_1_1request__writer.html#a4e864e362bfa9d132175f80503b32782" title="default destructor">~request_writer</a>() {}
<a name="l00038"></a>00038 
<a name="l00048"></a><a class="code" href="classpion_1_1http_1_1request__writer.html#a48f732224837b249560dedbaba56096d">00048</a>     <span class="keyword">static</span> <span class="keyword">inline</span> boost::shared_ptr&lt;request_writer&gt; <a class="code" href="classpion_1_1http_1_1request__writer.html#a48f732224837b249560dedbaba56096d">create</a>(tcp::connection_ptr&amp; tcp_conn,
<a name="l00049"></a>00049                                                               <a class="code" href="classpion_1_1http_1_1writer.html#a7e3ce4b88e0427adf673a99fca3af982" title="function called after the HTTP message has been sent">finished_handler_t</a> handler = <a class="code" href="classpion_1_1http_1_1writer.html#a7e3ce4b88e0427adf673a99fca3af982" title="function called after the HTTP message has been sent">finished_handler_t</a>())
<a name="l00050"></a>00050     {
<a name="l00051"></a>00051         <span class="keywordflow">return</span> boost::shared_ptr&lt;request_writer&gt;(<span class="keyword">new</span> <a class="code" href="classpion_1_1http_1_1request__writer.html#a5d7e26703684a0214af3ce5df33add84">request_writer</a>(tcp_conn, handler));
<a name="l00052"></a>00052     }
<a name="l00053"></a>00053     
<a name="l00064"></a><a class="code" href="classpion_1_1http_1_1request__writer.html#a2384146dc06aa0340ccbd6014bb0be8a">00064</a>     <span class="keyword">static</span> <span class="keyword">inline</span> boost::shared_ptr&lt;request_writer&gt; <a class="code" href="classpion_1_1http_1_1request__writer.html#a48f732224837b249560dedbaba56096d">create</a>(tcp::connection_ptr&amp; tcp_conn,
<a name="l00065"></a>00065                                                               http::request_ptr&amp; http_request_ptr,
<a name="l00066"></a>00066                                                               <a class="code" href="classpion_1_1http_1_1writer.html#a7e3ce4b88e0427adf673a99fca3af982" title="function called after the HTTP message has been sent">finished_handler_t</a> handler = <a class="code" href="classpion_1_1http_1_1writer.html#a7e3ce4b88e0427adf673a99fca3af982" title="function called after the HTTP message has been sent">finished_handler_t</a>())
<a name="l00067"></a>00067     {
<a name="l00068"></a>00068         <span class="keywordflow">return</span> boost::shared_ptr&lt;request_writer&gt;(<span class="keyword">new</span> <a class="code" href="classpion_1_1http_1_1request__writer.html#a5d7e26703684a0214af3ce5df33add84">request_writer</a>(tcp_conn, http_request_ptr, handler));
<a name="l00069"></a>00069     }
<a name="l00070"></a>00070 
<a name="l00072"></a><a class="code" href="classpion_1_1http_1_1request__writer.html#a16c7f5af36362dbb360fc46fd591c2b2">00072</a>     <span class="keyword">inline</span> <a class="code" href="classpion_1_1http_1_1request.html">http::request</a>&amp; <a class="code" href="classpion_1_1http_1_1request__writer.html#a16c7f5af36362dbb360fc46fd591c2b2" title="returns a non-const reference to the request that will be sent">get_request</a>(<span class="keywordtype">void</span>) { <span class="keywordflow">return</span> *m_http_request; }
<a name="l00073"></a>00073     
<a name="l00074"></a>00074     
<a name="l00075"></a>00075 <span class="keyword">protected</span>:
<a name="l00076"></a>00076     
<a name="l00083"></a><a class="code" href="classpion_1_1http_1_1request__writer.html#a5d7e26703684a0214af3ce5df33add84">00083</a>     <a class="code" href="classpion_1_1http_1_1request__writer.html#a5d7e26703684a0214af3ce5df33add84">request_writer</a>(tcp::connection_ptr&amp; tcp_conn, <a class="code" href="classpion_1_1http_1_1writer.html#a7e3ce4b88e0427adf673a99fca3af982" title="function called after the HTTP message has been sent">finished_handler_t</a> handler)
<a name="l00084"></a>00084         : http::<a class="code" href="classpion_1_1http_1_1writer.html">writer</a>(tcp_conn, handler), m_http_request(new http::<a class="code" href="classpion_1_1http_1_1request.html">request</a>)
<a name="l00085"></a>00085     {
<a name="l00086"></a>00086         <a class="code" href="classpion_1_1http_1_1writer.html#a25f0a6f75c22eb95d619ae600c0f2121" title="sets the logger to be used">set_logger</a>(PION_GET_LOGGER(<span class="stringliteral">&quot;pion.http.request_writer&quot;</span>));
<a name="l00087"></a>00087     }
<a name="l00088"></a>00088     
<a name="l00096"></a><a class="code" href="classpion_1_1http_1_1request__writer.html#a2b75e1dae183e7d7eaa43adbf8a36584">00096</a>     <a class="code" href="classpion_1_1http_1_1request__writer.html#a5d7e26703684a0214af3ce5df33add84">request_writer</a>(tcp::connection_ptr&amp; tcp_conn, http::request_ptr&amp; http_request_ptr,
<a name="l00097"></a>00097                       <a class="code" href="classpion_1_1http_1_1writer.html#a7e3ce4b88e0427adf673a99fca3af982" title="function called after the HTTP message has been sent">finished_handler_t</a> handler)
<a name="l00098"></a>00098         : http::<a class="code" href="classpion_1_1http_1_1writer.html">writer</a>(tcp_conn, handler), m_http_request(http_request_ptr)
<a name="l00099"></a>00099     {
<a name="l00100"></a>00100         <a class="code" href="classpion_1_1http_1_1writer.html#a25f0a6f75c22eb95d619ae600c0f2121" title="sets the logger to be used">set_logger</a>(PION_GET_LOGGER(<span class="stringliteral">&quot;pion.http.request_writer&quot;</span>));
<a name="l00101"></a>00101         <span class="comment">// check if we should initialize the payload content using</span>
<a name="l00102"></a>00102         <span class="comment">// the request&apos;s content buffer</span>
<a name="l00103"></a>00103         <span class="keywordflow">if</span> (m_http_request-&gt;get_content_length() &gt; 0
<a name="l00104"></a>00104             &amp;&amp; m_http_request-&gt;get_content() != NULL
<a name="l00105"></a>00105             &amp;&amp; m_http_request-&gt;get_content()[0] != <span class="charliteral">&apos;\0&apos;</span>)
<a name="l00106"></a>00106         {
<a name="l00107"></a>00107             <a class="code" href="classpion_1_1http_1_1writer.html#ad82908f247f558770c6c4d9f58d2a5f2">write_no_copy</a>(m_http_request-&gt;get_content(),
<a name="l00108"></a>00108                         m_http_request-&gt;get_content_length());
<a name="l00109"></a>00109         }
<a name="l00110"></a>00110     }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112     
<a name="l00118"></a><a class="code" href="classpion_1_1http_1_1request__writer.html#aeef6096bf4fa008248be93a3c3158c2d">00118</a>     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1http_1_1request__writer.html#aeef6096bf4fa008248be93a3c3158c2d">prepare_buffers_for_send</a>(<a class="code" href="classpion_1_1http_1_1message.html#aacf9a6a7677c32e4ab764ac97d0b5e7b" title="data type for I/O write buffers (these wrap existing data to be sent)">http::message::write_buffers_t</a>&amp; write_buffers) {
<a name="l00119"></a>00119         <span class="keywordflow">if</span> (<a class="code" href="classpion_1_1http_1_1writer.html#a980285662a960320b561e419563a83e2" title="returns the length of the payload content (in bytes)">get_content_length</a>() &gt; 0)
<a name="l00120"></a>00120             m_http_request-&gt;set_content_length(<a class="code" href="classpion_1_1http_1_1writer.html#a980285662a960320b561e419563a83e2" title="returns the length of the payload content (in bytes)">get_content_length</a>());
<a name="l00121"></a>00121         m_http_request-&gt;prepare_buffers_for_send(write_buffers,
<a name="l00122"></a>00122                                               <a class="code" href="classpion_1_1http_1_1writer.html#ae65148e4a1e72266e64c4ab1ceed2c17" title="returns a shared pointer to the TCP connection">get_connection</a>()-&gt;get_keep_alive(),
<a name="l00123"></a>00123                                               <a class="code" href="classpion_1_1http_1_1writer.html#a7a9f95f0cc0ccf1d091a94d5ba5ecebc" title="returns true if we are sending a chunked message to the client">sending_chunked_message</a>());
<a name="l00124"></a>00124     }
<a name="l00125"></a>00125 
<a name="l00127"></a><a class="code" href="classpion_1_1http_1_1request__writer.html#a1ac6c4591f4a936391e78f394e18c9ed">00127</a>     <span class="keyword">virtual</span> <a class="code" href="classpion_1_1http_1_1writer.html#a36fa31c850362d907559a0c1157a1bf3" title="data type for a function that handles write operations">write_handler_t</a> <a class="code" href="classpion_1_1http_1_1request__writer.html#a1ac6c4591f4a936391e78f394e18c9ed" title="returns a function bound to http::writer::handle_write()">bind_to_write_handler</a>(<span class="keywordtype">void</span>) {
<a name="l00128"></a>00128         <span class="keywordflow">return</span> boost::bind(&amp;<a class="code" href="classpion_1_1http_1_1request__writer.html#a8cb6beccbb5f89356be78935f2ca59d4">request_writer::handle_write</a>, shared_from_this(),
<a name="l00129"></a>00129                            boost::asio::placeholders::error,
<a name="l00130"></a>00130                            boost::asio::placeholders::bytes_transferred);
<a name="l00131"></a>00131     }
<a name="l00132"></a>00132 
<a name="l00139"></a><a class="code" href="classpion_1_1http_1_1request__writer.html#a8cb6beccbb5f89356be78935f2ca59d4">00139</a>     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classpion_1_1http_1_1request__writer.html#a8cb6beccbb5f89356be78935f2ca59d4">handle_write</a>(<span class="keyword">const</span> boost::system::error_code&amp; write_error,
<a name="l00140"></a>00140                              std::size_t bytes_written)
<a name="l00141"></a>00141     {
<a name="l00142"></a>00142         logger log_ptr(<a class="code" href="classpion_1_1http_1_1writer.html#a58c000ca432c7c168ebd666f4bd17c30" title="returns the logger currently in use">get_logger</a>());
<a name="l00143"></a>00143         <span class="keywordflow">if</span> (! write_error) {
<a name="l00144"></a>00144             <span class="comment">// request sent OK</span>
<a name="l00145"></a>00145             <span class="keywordflow">if</span> (<a class="code" href="classpion_1_1http_1_1writer.html#a7a9f95f0cc0ccf1d091a94d5ba5ecebc" title="returns true if we are sending a chunked message to the client">sending_chunked_message</a>()) {
<a name="l00146"></a>00146                 PION_LOG_DEBUG(log_ptr, <span class="stringliteral">&quot;Sent HTTP request chunk of &quot;</span> &lt;&lt; bytes_written &lt;&lt; <span class="stringliteral">&quot; bytes&quot;</span>);
<a name="l00147"></a>00147                 <a class="code" href="classpion_1_1http_1_1writer.html#a17e88be48ecde04b8dbe54239a14dc25" title="clears out all of the memory buffers used to cache payload content data">clear</a>();
<a name="l00148"></a>00148             } <span class="keywordflow">else</span> {
<a name="l00149"></a>00149                 PION_LOG_DEBUG(log_ptr, <span class="stringliteral">&quot;Sent HTTP request of &quot;</span> &lt;&lt; bytes_written &lt;&lt; <span class="stringliteral">&quot; bytes&quot;</span>);
<a name="l00150"></a>00150             }
<a name="l00151"></a>00151         }
<a name="l00152"></a>00152         <a class="code" href="classpion_1_1http_1_1writer.html#a28a73762ddc3c59091aa44d10adad5ea" title="called after we have finished sending the HTTP message">finished_writing</a>(write_error);
<a name="l00153"></a>00153     }
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 
<a name="l00156"></a>00156 <span class="keyword">private</span>:
<a name="l00157"></a>00157     
<a name="l00159"></a>00159     http::request_ptr       m_http_request;
<a name="l00160"></a>00160     
<a name="l00162"></a>00162     std::string             m_request_line;
<a name="l00163"></a>00163 };
<a name="l00164"></a>00164 
<a name="l00165"></a>00165 
<a name="l00167"></a>00167 <span class="keyword">typedef</span> boost::shared_ptr&lt;request_writer&gt;    request_writer_ptr;
<a name="l00168"></a>00168 
<a name="l00169"></a>00169 
<a name="l00171"></a>00171 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00172"></a>00172 <span class="keyword">const</span> request_writer_ptr&amp; operator&lt;&lt;(<span class="keyword">const</span> request_writer_ptr&amp; writer, <span class="keyword">const</span> T&amp; data) {
<a name="l00173"></a>00173     writer-&gt;write(data);
<a name="l00174"></a>00174     <span class="keywordflow">return</span> writer;
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176 
<a name="l00177"></a>00177 
<a name="l00178"></a>00178 }   <span class="comment">// end namespace http</span>
<a name="l00179"></a>00179 }   <span class="comment">// end namespace pion</span>
<a name="l00180"></a>00180 
<a name="l00181"></a>00181 <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&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>