Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) |
3 |
|
|
// |
4 |
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying |
5 |
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 |
|
|
// |
7 |
|
|
// Official repository: https://github.com/CPPAlliance/http_proto |
8 |
|
|
// |
9 |
|
|
|
10 |
|
|
#ifndef BOOST_HTTP_PROTO_IMPL_PARSER_HPP |
11 |
|
|
#define BOOST_HTTP_PROTO_IMPL_PARSER_HPP |
12 |
|
|
|
13 |
|
|
#include <cstdlib> |
14 |
|
|
|
15 |
|
|
namespace boost { |
16 |
|
|
namespace http_proto { |
17 |
|
|
|
18 |
|
|
//------------------------------------------------ |
19 |
|
|
|
20 |
|
|
template<class DynamicBuffer, class> |
21 |
|
|
typename std::decay< |
22 |
|
|
DynamicBuffer>::type& |
23 |
|
299 |
parser:: |
24 |
|
|
set_body( |
25 |
|
|
DynamicBuffer&& b) |
26 |
|
|
{ |
27 |
|
|
// body must not be set already |
28 |
|
299 |
if(how_ != how::in_place) |
29 |
|
✗ |
detail::throw_logic_error(); |
30 |
|
|
|
31 |
|
|
// headers must be complete |
32 |
|
299 |
if(! got_header()) |
33 |
|
✗ |
detail::throw_logic_error(); |
34 |
|
|
|
35 |
|
299 |
auto& dyn = ws_.push( |
36 |
|
|
buffers::any_dynamic_buffer_impl<typename |
37 |
|
|
std::decay<DynamicBuffer>::type, |
38 |
|
|
buffers_N>(std::forward< |
39 |
|
|
DynamicBuffer>(b))); |
40 |
|
299 |
dyn_ = &dyn; |
41 |
|
299 |
how_ = how::dynamic; |
42 |
|
299 |
on_set_body(); |
43 |
|
299 |
return dyn.buffer(); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
//------------------------------------------------ |
47 |
|
|
|
48 |
|
|
template<class Sink> |
49 |
|
|
typename std::enable_if< |
50 |
|
|
is_sink<Sink>::value, |
51 |
|
|
typename std::decay<Sink>::type |
52 |
|
|
>::type& |
53 |
|
|
parser:: |
54 |
|
|
set_body( |
55 |
|
|
Sink&& sink) |
56 |
|
|
{ |
57 |
|
|
// body must not be set already |
58 |
|
|
if(how_ != how::in_place) |
59 |
|
|
detail::throw_logic_error(); |
60 |
|
|
|
61 |
|
|
// headers must be complete |
62 |
|
|
if(! got_header()) |
63 |
|
|
detail::throw_logic_error(); |
64 |
|
|
|
65 |
|
|
auto& s = ws_.push( |
66 |
|
|
std::forward<Sink>(sink)); |
67 |
|
|
sink_ = &s; |
68 |
|
|
how_ = how::sink; |
69 |
|
|
on_set_body(); |
70 |
|
|
return s; |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
} // http_proto |
74 |
|
|
} // boost |
75 |
|
|
|
76 |
|
|
#endif |
77 |
|
|
|