37
37
38
38
#ifndef NETWORK_HTTP_SERVER_CONNECTION_HEADER_BUFFER_MAX_SIZE
39
39
/* * Here we define a page's worth of header connection buffer data.
40
- * This can be tuned to reduce the memory cost of connections, but this
40
+ * This can be tuned to reduce the memory cost of connections, but this
41
41
* default size is set to be friendly to typical service applications.
42
42
* This is the maximum size though and Boost.Asio's internal representation
43
43
* of a streambuf would make appropriate decisions on how big a buffer
@@ -91,7 +91,7 @@ namespace network { namespace http {
91
91
92
92
private:
93
93
static char const * status_message (status_t status) {
94
- static char const
94
+ static char const
95
95
ok_[] = " OK"
96
96
, created_[] = " Created"
97
97
, accepted_[] = " Accepted"
@@ -160,9 +160,9 @@ namespace network { namespace http {
160
160
161
161
/* * Function: template <class Range> set_headers(Range headers)
162
162
* Precondition: headers have not been sent yet
163
- * Postcondition: headers have been linearized to a buffer,
163
+ * Postcondition: headers have been linearized to a buffer,
164
164
* and assumed to have been sent already when the function exits
165
- * Throws: std::logic_error in case the headers have already been sent.
165
+ * Throws: std::logic_error in case the headers have already been sent.
166
166
*
167
167
* A call to set_headers takes a Range where each element models the
168
168
* Header concept. This Range will be linearized onto a buffer, which is
@@ -171,7 +171,7 @@ namespace network { namespace http {
171
171
template <class Range >
172
172
void set_headers (Range headers) {
173
173
lock_guard lock (headers_mutex);
174
- if (headers_in_progress || headers_already_sent)
174
+ if (headers_in_progress || headers_already_sent)
175
175
boost::throw_exception (std::logic_error (" Headers have already been sent." ));
176
176
177
177
if (error_encountered)
@@ -185,7 +185,7 @@ namespace network { namespace http {
185
185
<< constants::crlf ();
186
186
if (!boost::empty (headers)) {
187
187
typedef typename Range::const_iterator iterator;
188
- boost::transform (headers,
188
+ boost::transform (headers,
189
189
std::ostream_iterator<std::string>(stream),
190
190
linearize_header ());
191
191
} else {
@@ -213,7 +213,7 @@ namespace network { namespace http {
213
213
void write (Range const & range) {
214
214
lock_guard lock (headers_mutex);
215
215
if (error_encountered) boost::throw_exception (boost::system::system_error (*error_encountered));
216
- std::function<void (boost::system::error_code)> f =
216
+ std::function<void (boost::system::error_code)> f =
217
217
std::bind (
218
218
&async_server_connection::default_error
219
219
, async_server_connection::shared_from_this ()
@@ -319,7 +319,7 @@ namespace network { namespace http {
319
319
status_t status;
320
320
request_parser parser;
321
321
request request_;
322
- typename buffer_type::iterator new_start, data_end;
322
+ buffer_type::iterator new_start, data_end;
323
323
std::string partial_parsed;
324
324
boost::optional<boost::system::system_error> error_encountered;
325
325
pending_actions_list pending_actions;
@@ -365,7 +365,7 @@ namespace network { namespace http {
365
365
new_start, data_end);
366
366
boost::fusion::tie (parsed_ok, result_range) = parser.parse_until (
367
367
request_parser::method_done, input_range);
368
- if (!parsed_ok) {
368
+ if (!parsed_ok) {
369
369
client_error ();
370
370
break ;
371
371
} else if (parsed_ok == true ) {
@@ -479,7 +479,7 @@ namespace network { namespace http {
479
479
}
480
480
481
481
void client_error () {
482
- static char const * bad_request =
482
+ static char const * bad_request =
483
483
" HTTP/1.0 400 Bad Request\r\n Connection: close\r\n Content-Type: text/plain\r\n Content-Length: 12\r\n\r\n Bad Request." ;
484
484
485
485
boost::asio::async_write (
@@ -565,17 +565,17 @@ namespace network { namespace http {
565
565
566
566
static std::size_t const connection_buffer_size =
567
567
NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE;
568
- shared_array_list temporaries =
568
+ shared_array_list temporaries =
569
569
std::make_shared<array_list>();
570
- shared_buffers buffers =
570
+ shared_buffers buffers =
571
571
std::make_shared<std::vector<boost::asio::const_buffer> >(0 );
572
572
573
573
std::size_t range_size = boost::distance (range);
574
574
buffers->reserve (
575
575
(range_size / connection_buffer_size)
576
576
+ ((range_size % connection_buffer_size)?1 :0 )
577
577
);
578
- std::size_t slice_size =
578
+ std::size_t slice_size =
579
579
std::min (range_size,connection_buffer_size);
580
580
typename boost::range_iterator<Range>::type
581
581
start = boost::begin (range)
@@ -641,8 +641,8 @@ namespace network { namespace http {
641
641
);
642
642
}
643
643
};
644
-
644
+
645
645
} // namespace http
646
646
} // namespace network
647
-
647
+
648
648
#endif /* NETWORK_PROTOCOL_HTTP_SERVER_CONNECTION_HPP_20101027 */
0 commit comments