Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot 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_REQUEST_IPP | ||
11 | #define BOOST_HTTP_PROTO_IMPL_REQUEST_IPP | ||
12 | |||
13 | #include <boost/http_proto/request.hpp> | ||
14 | #include <boost/http_proto/request_view.hpp> | ||
15 | #include <boost/http_proto/detail/copied_strings.hpp> | ||
16 | #include <boost/http_proto/detail/number_string.hpp> | ||
17 | #include <utility> | ||
18 | |||
19 | namespace boost { | ||
20 | namespace http_proto { | ||
21 | |||
22 | 394 | request:: | |
23 | 394 | request() noexcept | |
24 | : fields_view_base( | ||
25 | 394 | &this->fields_base::h_) | |
26 | , message_base( | ||
27 | 394 | detail::kind::request) | |
28 | { | ||
29 | } | ||
30 | |||
31 | 44 | request:: | |
32 | request( | ||
33 | 44 | request&& other) noexcept | |
34 | : fields_view_base( | ||
35 | 44 | &this->fields_base::h_) | |
36 | , message_base( | ||
37 | 44 | detail::kind::request) | |
38 | { | ||
39 | 44 | swap(other); | |
40 | } | ||
41 | |||
42 | 4 | request:: | |
43 | request( | ||
44 | 4 | request const& other) | |
45 | : fields_view_base( | ||
46 | 4 | &this->fields_base::h_) | |
47 | 4 | , message_base(*other.ph_) | |
48 | { | ||
49 | } | ||
50 | |||
51 | ✗ | request:: | |
52 | request( | ||
53 | ✗ | request_view const& other) | |
54 | : fields_view_base( | ||
55 | ✗ | &this->fields_base::h_) | |
56 | ✗ | , message_base(*other.ph_) | |
57 | { | ||
58 | } | ||
59 | |||
60 | request& | ||
61 | 20 | request:: | |
62 | operator=( | ||
63 | request&& other) noexcept | ||
64 | { | ||
65 | request temp( | ||
66 | 20 | std::move(other)); | |
67 | 20 | temp.swap(*this); | |
68 | 20 | return *this; | |
69 | } | ||
70 | |||
71 | //------------------------------------------------ | ||
72 | |||
73 | void | ||
74 | 2 | request:: | |
75 | set_expect_100_continue(bool b) | ||
76 | { | ||
77 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if(h_.md.expect.count == 0) |
78 | { | ||
79 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | BOOST_ASSERT( |
80 | ! h_.md.expect.ec.failed()); | ||
81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | BOOST_ASSERT( |
82 | ! h_.md.expect.is_100_continue); | ||
83 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if(b) |
84 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | return append( |
85 | field::expect, | ||
86 | 1 | "100-continue"); | |
87 | ✗ | return; | |
88 | } | ||
89 | |||
90 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if(h_.md.expect.count == 1) |
91 | { | ||
92 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if(b) |
93 | { | ||
94 | ✗ | if(! h_.md.expect.ec.failed()) | |
95 | { | ||
96 | ✗ | BOOST_ASSERT( | |
97 | h_.md.expect.is_100_continue); | ||
98 | ✗ | return; | |
99 | } | ||
100 | ✗ | BOOST_ASSERT( | |
101 | ! h_.md.expect.is_100_continue); | ||
102 | ✗ | auto it = find(field::expect); | |
103 | ✗ | BOOST_ASSERT(it != end()); | |
104 | ✗ | erase(it); | |
105 | ✗ | return; | |
106 | } | ||
107 | |||
108 | 1 | auto it = find(field::expect); | |
109 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | BOOST_ASSERT(it != end()); |
110 | 1 | erase(it); | |
111 | 1 | return; | |
112 | } | ||
113 | |||
114 | ✗ | if(b) | |
115 | { | ||
116 | ✗ | if(! h_.md.expect.ec.failed()) | |
117 | { | ||
118 | // remove all but one | ||
119 | ✗ | raw_erase_n( | |
120 | field::expect, | ||
121 | ✗ | h_.md.expect.count - 1); | |
122 | ✗ | return; | |
123 | } | ||
124 | |||
125 | ✗ | erase(field::expect); | |
126 | ✗ | return append( | |
127 | field::expect, | ||
128 | ✗ | "100-continue"); | |
129 | } | ||
130 | |||
131 | ✗ | erase(field::expect); | |
132 | } | ||
133 | |||
134 | //------------------------------------------------ | ||
135 | |||
136 | void | ||
137 | 190 | request:: | |
138 | set_impl( | ||
139 | http_proto::method m, | ||
140 | string_view ms, | ||
141 | string_view t, | ||
142 | http_proto::version v) | ||
143 | { | ||
144 | detail::copied_strings cs( | ||
145 | 380 | this->buffer()); | |
146 |
1/2✓ Branch 1 taken 190 times.
✗ Branch 2 not taken.
|
190 | ms = cs.maybe_copy(ms); |
147 |
1/2✓ Branch 1 taken 190 times.
✗ Branch 2 not taken.
|
190 | t = cs.maybe_copy(t); |
148 | |||
149 | auto const vs = | ||
150 | 190 | to_string(v); | |
151 | auto const n = | ||
152 | 190 | ms.size() + 1 + | |
153 | 190 | t.size() + 1 + | |
154 | 190 | vs.size() + 2; | |
155 |
2/2✓ Branch 1 taken 189 times.
✓ Branch 2 taken 1 times.
|
190 | auto dest = set_prefix_impl(n); |
156 | 189 | std::memcpy( | |
157 | dest, | ||
158 | 189 | ms.data(), | |
159 | ms.size()); | ||
160 | 189 | dest += ms.size(); | |
161 | 189 | *dest++ = ' '; | |
162 | 189 | std::memcpy( | |
163 | dest, | ||
164 | 189 | t.data(), | |
165 | t.size()); | ||
166 | 189 | dest += t.size(); | |
167 | 189 | *dest++ = ' '; | |
168 | 189 | std::memcpy( | |
169 | dest, | ||
170 | 189 | vs.data(), | |
171 | vs.size()); | ||
172 | 189 | dest += vs.size(); | |
173 | 189 | *dest++ = '\r'; | |
174 | 189 | *dest++ = '\n'; | |
175 | |||
176 | 189 | h_.version = v; | |
177 | 189 | h_.req.method = m; | |
178 | 189 | h_.req.method_len = | |
179 | 189 | static_cast<off_t>(ms.size()); | |
180 | 189 | h_.req.target_len = | |
181 | 189 | static_cast<off_t>(t.size()); | |
182 | |||
183 | 189 | h_.on_start_line(); | |
184 | 189 | } | |
185 | |||
186 | } // http_proto | ||
187 | } // boost | ||
188 | |||
189 | #endif | ||
190 |