| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-02-21 07:00:31 -08:00
										 |  |  | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
 | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | //
 | 
					
						
							|  |  |  | // Distributed under the Boost Software License, Version 1.0. (See accompanying
 | 
					
						
							|  |  |  | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2017-07-20 13:40:34 -07:00
										 |  |  | // Official repository: https://github.com/boostorg/beast
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-22 13:06:43 -08:00
										 |  |  | #ifndef BOOST_BEAST_HTTP_IMPL_BASIC_PARSER_HPP
 | 
					
						
							|  |  |  | #define BOOST_BEAST_HTTP_IMPL_BASIC_PARSER_HPP
 | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-05 08:25:54 -08:00
										 |  |  | #include <boost/beast/core/buffer_traits.hpp>
 | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | #include <boost/asio/buffer.hpp>
 | 
					
						
							| 
									
										
										
										
											2017-07-08 20:45:35 -07:00
										 |  |  | #include <boost/make_unique.hpp>
 | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-20 13:40:34 -07:00
										 |  |  | namespace boost { | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | namespace beast { | 
					
						
							|  |  |  | namespace http { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 06:55:12 -08:00
										 |  |  | template<bool isRequest> | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | template<class ConstBufferSequence> | 
					
						
							|  |  |  | std::size_t | 
					
						
							| 
									
										
										
										
											2019-02-23 06:55:12 -08:00
										 |  |  | basic_parser<isRequest>:: | 
					
						
							| 
									
										
										
										
											2017-05-31 08:01:55 -07:00
										 |  |  | put(ConstBufferSequence const& buffers, | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  |     error_code& ec) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-30 14:58:38 -08:00
										 |  |  |     static_assert(net::is_const_buffer_sequence< | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  |         ConstBufferSequence>::value, | 
					
						
							| 
									
										
										
										
											2019-02-20 19:19:59 -08:00
										 |  |  |             "ConstBufferSequence type requirements not met"); | 
					
						
							| 
									
										
										
										
											2018-11-30 14:58:38 -08:00
										 |  |  |     auto const p = net::buffer_sequence_begin(buffers); | 
					
						
							|  |  |  |     auto const last = net::buffer_sequence_end(buffers); | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  |     if(p == last) | 
					
						
							| 
									
										
										
										
											2017-06-13 07:08:52 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-01-20 09:50:43 -08:00
										 |  |  |         ec = {}; | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2017-06-13 07:08:52 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  |     if(std::next(p) == last) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // single buffer
 | 
					
						
							| 
									
										
										
										
											2018-11-30 14:58:38 -08:00
										 |  |  |         return put(net::const_buffer(*p), ec); | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-03-05 08:47:02 -08:00
										 |  |  |     auto const size = buffer_bytes(buffers); | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  |     if(size <= max_stack_buffer) | 
					
						
							|  |  |  |         return put_from_stack(size, buffers, ec); | 
					
						
							|  |  |  |     if(size > buf_len_) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // reallocate
 | 
					
						
							| 
									
										
										
										
											2017-07-08 20:45:35 -07:00
										 |  |  |         buf_ = boost::make_unique_noinit<char[]>(size); | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  |         buf_len_ = size; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // flatten
 | 
					
						
							| 
									
										
										
										
											2019-02-02 10:53:54 -08:00
										 |  |  |     net::buffer_copy(net::buffer( | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  |         buf_.get(), buf_len_), buffers); | 
					
						
							| 
									
										
										
										
											2018-11-30 14:58:38 -08:00
										 |  |  |     return put(net::const_buffer{ | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  |         buf_.get(), buf_len_}, ec); | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 06:55:12 -08:00
										 |  |  | template<bool isRequest> | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | template<class ConstBufferSequence> | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  | std::size_t | 
					
						
							| 
									
										
										
										
											2019-02-23 06:55:12 -08:00
										 |  |  | basic_parser<isRequest>:: | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  | put_from_stack(std::size_t size, | 
					
						
							|  |  |  |     ConstBufferSequence const& buffers, | 
					
						
							|  |  |  |         error_code& ec) | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  |     char buf[max_stack_buffer]; | 
					
						
							| 
									
										
										
										
											2019-02-02 10:53:54 -08:00
										 |  |  |     net::buffer_copy(net::mutable_buffer( | 
					
						
							|  |  |  |         buf, sizeof(buf)), buffers); | 
					
						
							| 
									
										
										
										
											2018-11-30 14:58:38 -08:00
										 |  |  |     return put(net::const_buffer{ | 
					
						
							| 
									
										
										
										
											2017-06-11 17:55:05 -07:00
										 |  |  |         buf, size}, ec); | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // http
 | 
					
						
							|  |  |  | } // beast
 | 
					
						
							| 
									
										
										
										
											2017-07-20 13:40:34 -07:00
										 |  |  | } // boost
 | 
					
						
							| 
									
										
										
										
											2016-11-20 07:32:41 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif
 |