77.25% Lines (533/690) 84.13% Functions (53/63)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3   // Copyright (c) 2024 Mohammad Nejati 3   // Copyright (c) 2024 Mohammad Nejati
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 5   // Distributed under the Boost Software License, Version 1.0. (See accompanying
6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/cppalliance/http 8   // Official repository: https://github.com/cppalliance/http
9   // 9   //
10   10  
11   #include <boost/http/detail/except.hpp> 11   #include <boost/http/detail/except.hpp>
12   #include <boost/http/detail/workspace.hpp> 12   #include <boost/http/detail/workspace.hpp>
13   #include <boost/http/error.hpp> 13   #include <boost/http/error.hpp>
14   #include <boost/http/parser.hpp> 14   #include <boost/http/parser.hpp>
15   #include <boost/http/static_request.hpp> 15   #include <boost/http/static_request.hpp>
16   #include <boost/http/static_response.hpp> 16   #include <boost/http/static_response.hpp>
17   17  
18   #include <boost/http/detail/circular_buffer.hpp> 18   #include <boost/http/detail/circular_buffer.hpp>
19   #include <boost/http/detail/flat_buffer.hpp> 19   #include <boost/http/detail/flat_buffer.hpp>
20   20  
21   #include <boost/assert.hpp> 21   #include <boost/assert.hpp>
22   #include <boost/capy/buffers/buffer_copy.hpp> 22   #include <boost/capy/buffers/buffer_copy.hpp>
23   #include <boost/capy/buffers/buffers_front.hpp> 23   #include <boost/capy/buffers/buffers_front.hpp>
24   #include <boost/capy/ex/system_context.hpp> 24   #include <boost/capy/ex/system_context.hpp>
25   #include <boost/http/brotli/decode.hpp> 25   #include <boost/http/brotli/decode.hpp>
26   #include <boost/http/zlib/error.hpp> 26   #include <boost/http/zlib/error.hpp>
27   #include <boost/http/zlib/inflate.hpp> 27   #include <boost/http/zlib/inflate.hpp>
28   #include <boost/url/grammar/ci_string.hpp> 28   #include <boost/url/grammar/ci_string.hpp>
29   #include <boost/url/grammar/error.hpp> 29   #include <boost/url/grammar/error.hpp>
30   #include <boost/url/grammar/hexdig_chars.hpp> 30   #include <boost/url/grammar/hexdig_chars.hpp>
31   31  
32   #include "src/detail/brotli_filter_base.hpp" 32   #include "src/detail/brotli_filter_base.hpp"
33   #include "src/detail/buffer_utils.hpp" 33   #include "src/detail/buffer_utils.hpp"
34   #include "src/detail/zlib_filter_base.hpp" 34   #include "src/detail/zlib_filter_base.hpp"
35   35  
36   #include <array> 36   #include <array>
37   #include <memory> 37   #include <memory>
38   38  
39   namespace boost { 39   namespace boost {
40   namespace http { 40   namespace http {
41   41  
42   /* 42   /*
43   Principles for fixed-size buffer design 43   Principles for fixed-size buffer design
44   44  
45   axiom 1: 45   axiom 1:
46   To read data you must have a buffer. 46   To read data you must have a buffer.
47   47  
48   axiom 2: 48   axiom 2:
49   The size of the HTTP header is not 49   The size of the HTTP header is not
50   known in advance. 50   known in advance.
51   51  
52   conclusion 3: 52   conclusion 3:
53   A single I/O can produce a complete 53   A single I/O can produce a complete
54   HTTP header and additional payload 54   HTTP header and additional payload
55   data. 55   data.
56   56  
57   conclusion 4: 57   conclusion 4:
58   A single I/O can produce multiple 58   A single I/O can produce multiple
59   complete HTTP headers, complete 59   complete HTTP headers, complete
60   payloads, and a partial header or 60   payloads, and a partial header or
61   payload. 61   payload.
62   62  
63   axiom 5: 63   axiom 5:
64   A process is in one of two states: 64   A process is in one of two states:
65   1. at or below capacity 65   1. at or below capacity
66   2. above capacity 66   2. above capacity
67   67  
68   axiom 6: 68   axiom 6:
69   A program which can allocate an 69   A program which can allocate an
70   unbounded number of resources can 70   unbounded number of resources can
71   go above capacity. 71   go above capacity.
72   72  
73   conclusion 7: 73   conclusion 7:
74   A program can guarantee never going 74   A program can guarantee never going
75   above capacity if all resources are 75   above capacity if all resources are
76   provisioned at program startup. 76   provisioned at program startup.
77   77  
78   corollary 8: 78   corollary 8:
79   `parser` and `serializer` should each 79   `parser` and `serializer` should each
80   allocate a single buffer of calculated 80   allocate a single buffer of calculated
81   size, and never resize it. 81   size, and never resize it.
82   82  
83   axiom #: 83   axiom #:
84   A parser and a serializer are always 84   A parser and a serializer are always
85   used in pairs. 85   used in pairs.
86   86  
87   Buffer Usage 87   Buffer Usage
88   88  
89   | | begin 89   | | begin
90   | H | p | | f | read headers 90   | H | p | | f | read headers
91   | H | p | | T | f | set T body 91   | H | p | | T | f | set T body
92   | H | p | | C | T | f | make codec C 92   | H | p | | C | T | f | make codec C
93   | H | p | b | C | T | f | decode p into b 93   | H | p | b | C | T | f | decode p into b
94   | H | p | b | C | T | f | read/parse loop 94   | H | p | b | C | T | f | read/parse loop
95   | H | | T | f | destroy codec 95   | H | | T | f | destroy codec
96   | H | | T | f | finished 96   | H | | T | f | finished
97   97  
98   H headers 98   H headers
99   C codec 99   C codec
100   T body 100   T body
101   f table 101   f table
102   p partial payload 102   p partial payload
103   b body data 103   b body data
104   104  
105   "payload" is the bytes coming in from 105   "payload" is the bytes coming in from
106   the stream. 106   the stream.
107   107  
108   "body" is the logical body, after transfer 108   "body" is the logical body, after transfer
109   encoding is removed. This can be the 109   encoding is removed. This can be the
110   same as the payload. 110   same as the payload.
111   111  
112   A "plain payload" is when the payload and 112   A "plain payload" is when the payload and
113   body are identical (no transfer encodings). 113   body are identical (no transfer encodings).
114   114  
115   A "buffered payload" is any payload which is 115   A "buffered payload" is any payload which is
116   not plain. A second buffer is required 116   not plain. A second buffer is required
117   for reading. 117   for reading.
118   118  
119   "overread" is additional data received past 119   "overread" is additional data received past
120   the end of the headers when reading headers, 120   the end of the headers when reading headers,
121   or additional data received past the end of 121   or additional data received past the end of
122   the message payload. 122   the message payload.
123   */ 123   */
124   124  
125   namespace { 125   namespace {
126   126  
127   // Construct a 2-element const_buffer pair representing the first 127   // Construct a 2-element const_buffer pair representing the first
128   // `n` bytes of `src`. Replaces the pre-#262 `capy::prefix(src, n)` 128   // `n` bytes of `src`. Replaces the pre-#262 `capy::prefix(src, n)`
129   // idiom which yielded a slice convertible to std::array. 129   // idiom which yielded a slice convertible to std::array.
130   inline std::array<capy::const_buffer, 2> 130   inline std::array<capy::const_buffer, 2>
HITCBC 131   41598 prefix_pair( 131   41598 prefix_pair(
132   std::array<capy::const_buffer, 2> const& src, 132   std::array<capy::const_buffer, 2> const& src,
133   std::size_t n) noexcept 133   std::size_t n) noexcept
134   { 134   {
HITCBC 135   41598 std::array<capy::const_buffer, 2> result{}; 135   41598 std::array<capy::const_buffer, 2> result{};
HITCBC 136   41598 if(n <= src[0].size()) 136   41598 if(n <= src[0].size())
137   { 137   {
HITCBC 138   41099 result[0] = capy::const_buffer(src[0].data(), n); 138   41099 result[0] = capy::const_buffer(src[0].data(), n);
139   } 139   }
140   else 140   else
141   { 141   {
HITCBC 142   499 result[0] = src[0]; 142   499 result[0] = src[0];
HITCBC 143   499 std::size_t remaining = n - src[0].size(); 143   499 std::size_t remaining = n - src[0].size();
HITCBC 144   499 if(remaining > src[1].size()) 144   499 if(remaining > src[1].size())
MISUBC 145   ✗ remaining = src[1].size(); 145   ✗ remaining = src[1].size();
HITCBC 146   499 result[1] = capy::const_buffer(src[1].data(), remaining); 146   499 result[1] = capy::const_buffer(src[1].data(), remaining);
147   } 147   }
HITCBC 148   41598 return result; 148   41598 return result;
149   } 149   }
150   150  
151   class chained_sequence 151   class chained_sequence
152   { 152   {
153   char const* pos_; 153   char const* pos_;
154   char const* end_; 154   char const* end_;
155   char const* begin_b_; 155   char const* begin_b_;
156   char const* end_b_; 156   char const* end_b_;
157   157  
158   public: 158   public:
HITCBC 159   71617 chained_sequence(std::array<capy::const_buffer, 2> const& cbp) 159   71617 chained_sequence(std::array<capy::const_buffer, 2> const& cbp)
HITCBC 160   71617 : pos_(static_cast<char const*>(cbp[0].data())) 160   71617 : pos_(static_cast<char const*>(cbp[0].data()))
HITCBC 161   71617 , end_(pos_ + cbp[0].size()) 161   71617 , end_(pos_ + cbp[0].size())
HITCBC 162   71617 , begin_b_(static_cast<char const*>(cbp[1].data())) 162   71617 , begin_b_(static_cast<char const*>(cbp[1].data()))
HITCBC 163   71617 , end_b_(begin_b_ + cbp[1].size()) 163   71617 , end_b_(begin_b_ + cbp[1].size())
164   { 164   {
HITCBC 165   71617 } 165   71617 }
166   166  
167   char const* 167   char const*
HITCBC 168   319930 next() noexcept 168   319930 next() noexcept
169   { 169   {
HITCBC 170   319930 ++pos_; 170   319930 ++pos_;
171   // most frequently taken branch 171   // most frequently taken branch
HITCBC 172   319930 if(pos_ < end_) 172   319930 if(pos_ < end_)
HITCBC 173   297556 return pos_; 173   297556 return pos_;
174   174  
175   // bring the second range 175   // bring the second range
HITCBC 176   22374 if(begin_b_ != end_b_) 176   22374 if(begin_b_ != end_b_)
177   { 177   {
MISUBC 178   ✗ pos_ = begin_b_; 178   ✗ pos_ = begin_b_;
MISUBC 179   ✗ end_ = end_b_; 179   ✗ end_ = end_b_;
MISUBC 180   ✗ begin_b_ = end_b_; 180   ✗ begin_b_ = end_b_;
MISUBC 181   ✗ return pos_; 181   ✗ return pos_;
182   } 182   }
183   183  
184   // undo the increament 184   // undo the increament
HITCBC 185   22374 pos_ = end_; 185   22374 pos_ = end_;
HITCBC 186   22374 return nullptr; 186   22374 return nullptr;
187   } 187   }
188   188  
189   bool 189   bool
HITCBC 190   212674 is_empty() const noexcept 190   212674 is_empty() const noexcept
191   { 191   {
HITCBC 192   212674 return pos_ == end_; 192   212674 return pos_ == end_;
193   } 193   }
194   194  
195   char 195   char
HITCBC 196   305475 value() const noexcept 196   305475 value() const noexcept
197   { 197   {
HITCBC 198   305475 return *pos_; 198   305475 return *pos_;
199   } 199   }
200   200  
201   std::size_t 201   std::size_t
HITCBC 202   226936 size() const noexcept 202   226936 size() const noexcept
203   { 203   {
HITCBC 204   226936 return (end_ - pos_) + (end_b_ - begin_b_); 204   226936 return (end_ - pos_) + (end_b_ - begin_b_);
205   } 205   }
206   }; 206   };
207   207  
208   std::uint64_t 208   std::uint64_t
HITCBC 209   66939 parse_hex( 209   66939 parse_hex(
210   chained_sequence& cs, 210   chained_sequence& cs,
211   std::error_code& ec) noexcept 211   std::error_code& ec) noexcept
212   { 212   {
HITCBC 213   66939 std::uint64_t v = 0; 213   66939 std::uint64_t v = 0;
HITCBC 214   66939 std::size_t init_size = cs.size(); 214   66939 std::size_t init_size = cs.size();
HITCBC 215   154117 while(!cs.is_empty()) 215   154117 while(!cs.is_empty())
216   { 216   {
HITCBC 217   134169 auto n = grammar::hexdig_value(cs.value()); 217   134169 auto n = grammar::hexdig_value(cs.value());
HITCBC 218   134169 if(n < 0) 218   134169 if(n < 0)
219   { 219   {
HITCBC 220   46990 if(init_size == cs.size()) 220   46990 if(init_size == cs.size())
221   { 221   {
HITCBC 222   1 ec = error::bad_payload; 222   1 ec = error::bad_payload;
HITCBC 223   1 return 0; 223   1 return 0;
224   } 224   }
HITCBC 225   46989 return v; 225   46989 return v;
226   } 226   }
227   227  
228   // at least 4 significant bits are free 228   // at least 4 significant bits are free
HITCBC 229   87179 if(v > (std::numeric_limits<std::uint64_t>::max)() >> 4) 229   87179 if(v > (std::numeric_limits<std::uint64_t>::max)() >> 4)
230   { 230   {
HITCBC 231   1 ec = error::bad_payload; 231   1 ec = error::bad_payload;
HITCBC 232   1 return 0; 232   1 return 0;
233   } 233   }
234   234  
HITCBC 235   87178 v = (v << 4) | static_cast<std::uint64_t>(n); 235   87178 v = (v << 4) | static_cast<std::uint64_t>(n);
HITCBC 236   87178 cs.next(); 236   87178 cs.next();
237   } 237   }
HITCBC 238   19948 ec = error::need_data; 238   19948 ec = error::need_data;
HITCBC 239   19948 return 0; 239   19948 return 0;
240   } 240   }
241   241  
242   void 242   void
HITCBC 243   47341 find_eol( 243   47341 find_eol(
244   chained_sequence& cs, 244   chained_sequence& cs,
245   std::error_code& ec) noexcept 245   std::error_code& ec) noexcept
246   { 246   {
HITCBC 247   54030 while(!cs.is_empty()) 247   54030 while(!cs.is_empty())
248   { 248   {
HITCBC 249   53942 if(cs.value() == '\r') 249   53942 if(cs.value() == '\r')
250   { 250   {
HITCBC 251   47253 if(!cs.next()) 251   47253 if(!cs.next())
HITCBC 252   330 break; 252   330 break;
HITCBC 253   46923 if(cs.value() != '\n') 253   46923 if(cs.value() != '\n')
254   { 254   {
HITCBC 255   2 ec = error::bad_payload; 255   2 ec = error::bad_payload;
HITCBC 256   2 return; 256   2 return;
257   } 257   }
HITCBC 258   46921 cs.next(); 258   46921 cs.next();
HITCBC 259   46921 return; 259   46921 return;
260   } 260   }
HITCBC 261   6689 cs.next(); 261   6689 cs.next();
262   } 262   }
HITCBC 263   418 ec = error::need_data; 263   418 ec = error::need_data;
264   } 264   }
265   265  
266   void 266   void
HITCBC 267   62239 parse_eol( 267   62239 parse_eol(
268   chained_sequence& cs, 268   chained_sequence& cs,
269   std::error_code& ec) noexcept 269   std::error_code& ec) noexcept
270   { 270   {
HITCBC 271   62239 if(cs.size() >= 2) 271   62239 if(cs.size() >= 2)
272   { 272   {
273   // we are sure size is at least 2 273   // we are sure size is at least 2
HITCBC 274   61807 if(cs.value() == '\r' && *cs.next() == '\n') 274   61807 if(cs.value() == '\r' && *cs.next() == '\n')
275   { 275   {
HITCBC 276   61804 cs.next(); 276   61804 cs.next();
HITCBC 277   61804 return; 277   61804 return;
278   } 278   }
HITCBC 279   3 ec = error::bad_payload; 279   3 ec = error::bad_payload;
HITCBC 280   3 return; 280   3 return;
281   } 281   }
HITCBC 282   432 ec = error::need_data; 282   432 ec = error::need_data;
283   } 283   }
284   284  
285   void 285   void
HITCBC 286   4243 skip_trailer_headers( 286   4243 skip_trailer_headers(
287   chained_sequence& cs, 287   chained_sequence& cs,
288   std::error_code& ec) noexcept 288   std::error_code& ec) noexcept
289   { 289   {
HITCBC 290   4527 while(!cs.is_empty()) 290   4527 while(!cs.is_empty())
291   { 291   {
HITCBC 292   4501 if(cs.value() == '\r') 292   4501 if(cs.value() == '\r')
293   { 293   {
HITCBC 294   4149 if(!cs.next()) 294   4149 if(!cs.next())
HITCBC 295   16 break; 295   16 break;
HITCBC 296   4133 if(cs.value() != '\n') 296   4133 if(cs.value() != '\n')
297   { 297   {
HITCBC 298   2 ec = error::bad_payload; 298   2 ec = error::bad_payload;
HITCBC 299   2 return; 299   2 return;
300   } 300   }
HITCBC 301   4131 cs.next(); 301   4131 cs.next();
HITCBC 302   4131 return; 302   4131 return;
303   } 303   }
304   // skip to the end of field 304   // skip to the end of field
HITCBC 305   352 find_eol(cs, ec); 305   352 find_eol(cs, ec);
HITCBC 306   352 if(ec) 306   352 if(ec)
HITCBC 307   68 return; 307   68 return;
308   } 308   }
HITCBC 309   42 ec = error::need_data; 309   42 ec = error::need_data;
310   } 310   }
311   311  
312   template<class UInt> 312   template<class UInt>
313   std::size_t 313   std::size_t
HITCBC 314   193635 clamp( 314   193635 clamp(
315   UInt x, 315   UInt x,
316   std::size_t limit = (std::numeric_limits< 316   std::size_t limit = (std::numeric_limits<
317   std::size_t>::max)()) noexcept 317   std::size_t>::max)()) noexcept
318   { 318   {
HITCBC 319   193635 if(x >= limit) 319   193635 if(x >= limit)
HITCBC 320   46531 return limit; 320   46531 return limit;
HITCBC 321   147104 return static_cast<std::size_t>(x); 321   147104 return static_cast<std::size_t>(x);
322   } 322   }
323   323  
324   class zlib_filter 324   class zlib_filter
325   : public detail::zlib_filter_base 325   : public detail::zlib_filter_base
326   { 326   {
327   http::zlib::inflate_service& svc_; 327   http::zlib::inflate_service& svc_;
328   328  
329   public: 329   public:
MISUBC 330   ✗ zlib_filter( 330   ✗ zlib_filter(
331   http::zlib::inflate_service& svc, 331   http::zlib::inflate_service& svc,
332   int window_bits) 332   int window_bits)
MISUBC 333   ✗ : svc_(svc) 333   ✗ : svc_(svc)
334   { 334   {
335   std::error_code ec = static_cast<http::zlib::error>( 335   std::error_code ec = static_cast<http::zlib::error>(
MISUBC 336   ✗ svc_.init2(strm_, window_bits)); 336   ✗ svc_.init2(strm_, window_bits));
MISUBC 337   ✗ if(ec != http::zlib::error::ok) 337   ✗ if(ec != http::zlib::error::ok)
MISUBC 338   ✗ detail::throw_system_error(ec); 338   ✗ detail::throw_system_error(ec);
MISUBC 339   ✗ } 339   ✗ }
340   340  
MISUBC 341   ✗ ~zlib_filter() 341   ✗ ~zlib_filter()
MISUBC 342   ✗ { 342   ✗ {
MISUBC 343   ✗ svc_.inflate_end(strm_); 343   ✗ svc_.inflate_end(strm_);
MISUBC 344   ✗ } 344   ✗ }
345   345  
346   private: 346   private:
347   virtual 347   virtual
348   results 348   results
MISUBC 349   ✗ do_process( 349   ✗ do_process(
350   capy::mutable_buffer out, 350   capy::mutable_buffer out,
351   capy::const_buffer in, 351   capy::const_buffer in,
352   bool more) noexcept override 352   bool more) noexcept override
353   { 353   {
MISUBC 354   ✗ strm_.next_out = static_cast<unsigned char*>(out.data()); 354   ✗ strm_.next_out = static_cast<unsigned char*>(out.data());
MISUBC 355   ✗ strm_.avail_out = saturate_cast(out.size()); 355   ✗ strm_.avail_out = saturate_cast(out.size());
MISUBC 356   ✗ strm_.next_in = static_cast<unsigned char*>(const_cast<void *>(in.data())); 356   ✗ strm_.next_in = static_cast<unsigned char*>(const_cast<void *>(in.data()));
MISUBC 357   ✗ strm_.avail_in = saturate_cast(in.size()); 357   ✗ strm_.avail_in = saturate_cast(in.size());
358   358  
359   auto rs = static_cast<http::zlib::error>( 359   auto rs = static_cast<http::zlib::error>(
MISUBC 360   ✗ svc_.inflate( 360   ✗ svc_.inflate(
MISUBC 361   ✗ strm_, 361   ✗ strm_,
362   more ? http::zlib::no_flush : http::zlib::finish)); 362   more ? http::zlib::no_flush : http::zlib::finish));
363   363  
MISUBC 364   ✗ results rv; 364   ✗ results rv;
MISUBC 365   ✗ rv.out_bytes = saturate_cast(out.size()) - strm_.avail_out; 365   ✗ rv.out_bytes = saturate_cast(out.size()) - strm_.avail_out;
MISUBC 366   ✗ rv.in_bytes = saturate_cast(in.size()) - strm_.avail_in; 366   ✗ rv.in_bytes = saturate_cast(in.size()) - strm_.avail_in;
MISUBC 367   ✗ rv.finished = (rs == http::zlib::error::stream_end); 367   ✗ rv.finished = (rs == http::zlib::error::stream_end);
368   368  
MISUBC 369   ✗ if(rs < http::zlib::error::ok && rs != http::zlib::error::buf_err) 369   ✗ if(rs < http::zlib::error::ok && rs != http::zlib::error::buf_err)
MISUBC 370   ✗ rv.ec = rs; 370   ✗ rv.ec = rs;
371   371  
MISUBC 372   ✗ return rv; 372   ✗ return rv;
373   } 373   }
374   }; 374   };
375   375  
376   class brotli_filter 376   class brotli_filter
377   : public detail::brotli_filter_base 377   : public detail::brotli_filter_base
378   { 378   {
379   http::brotli::decode_service& svc_; 379   http::brotli::decode_service& svc_;
380   http::brotli::decoder_state* state_; 380   http::brotli::decoder_state* state_;
381   381  
382   public: 382   public:
MISUBC 383   ✗ brotli_filter(http::brotli::decode_service& svc) 383   ✗ brotli_filter(http::brotli::decode_service& svc)
MISUBC 384   ✗ : svc_(svc) 384   ✗ : svc_(svc)
385   { 385   {
MISUBC 386   ✗ state_ = svc_.create_instance(nullptr, nullptr, nullptr); 386   ✗ state_ = svc_.create_instance(nullptr, nullptr, nullptr);
MISUBC 387   ✗ if(!state_) 387   ✗ if(!state_)
MISUBC 388   ✗ detail::throw_bad_alloc(); 388   ✗ detail::throw_bad_alloc();
MISUBC 389   ✗ } 389   ✗ }
390   390  
MISUBC 391   ✗ ~brotli_filter() 391   ✗ ~brotli_filter()
MISUBC 392   ✗ { 392   ✗ {
MISUBC 393   ✗ svc_.destroy_instance(state_); 393   ✗ svc_.destroy_instance(state_);
MISUBC 394   ✗ } 394   ✗ }
395   395  
396   private: 396   private:
397   virtual 397   virtual
398   results 398   results
MISUBC 399   ✗ do_process( 399   ✗ do_process(
400   capy::mutable_buffer out, 400   capy::mutable_buffer out,
401   capy::const_buffer in, 401   capy::const_buffer in,
402   bool more) noexcept override 402   bool more) noexcept override
403   { 403   {
MISUBC 404   ✗ auto* next_in = reinterpret_cast<const std::uint8_t*>(in.data()); 404   ✗ auto* next_in = reinterpret_cast<const std::uint8_t*>(in.data());
MISUBC 405   ✗ auto available_in = in.size(); 405   ✗ auto available_in = in.size();
MISUBC 406   ✗ auto* next_out = reinterpret_cast<std::uint8_t*>(out.data()); 406   ✗ auto* next_out = reinterpret_cast<std::uint8_t*>(out.data());
MISUBC 407   ✗ auto available_out = out.size(); 407   ✗ auto available_out = out.size();
408   408  
MISUBC 409   ✗ auto rs = svc_.decompress_stream( 409   ✗ auto rs = svc_.decompress_stream(
410   state_, 410   state_,
411   &available_in, 411   &available_in,
412   &next_in, 412   &next_in,
413   &available_out, 413   &available_out,
414   &next_out, 414   &next_out,
415   nullptr); 415   nullptr);
416   416  
MISUBC 417   ✗ results rv; 417   ✗ results rv;
MISUBC 418   ✗ rv.in_bytes = in.size() - available_in; 418   ✗ rv.in_bytes = in.size() - available_in;
MISUBC 419   ✗ rv.out_bytes = out.size() - available_out; 419   ✗ rv.out_bytes = out.size() - available_out;
MISUBC 420   ✗ rv.finished = svc_.is_finished(state_); 420   ✗ rv.finished = svc_.is_finished(state_);
421   421  
MISUBC 422   ✗ if(!more && rs == http::brotli::decoder_result::needs_more_input) 422   ✗ if(!more && rs == http::brotli::decoder_result::needs_more_input)
MISUBC 423   ✗ rv.ec = error::bad_payload; 423   ✗ rv.ec = error::bad_payload;
424   424  
MISUBC 425   ✗ if(rs == http::brotli::decoder_result::error) 425   ✗ if(rs == http::brotli::decoder_result::error)
MISUBC 426   ✗ rv.ec = svc_.get_error_code(state_); 426   ✗ rv.ec = svc_.get_error_code(state_);
427   427  
MISUBC 428   ✗ return rv; 428   ✗ return rv;
429   } 429   }
430   }; 430   };
431   431  
432   } // namespace 432   } // namespace
433   433  
434   //------------------------------------------------ 434   //------------------------------------------------
435   435  
436   class parser::impl 436   class parser::impl
437   { 437   {
438   enum class state 438   enum class state
439   { 439   {
440   reset, 440   reset,
441   start, 441   start,
442   header, 442   header,
443   header_done, 443   header_done,
444   body, 444   body,
445   complete, 445   complete,
446   }; 446   };
447   447  
448   std::shared_ptr<parser_config_impl const> cfg_; 448   std::shared_ptr<parser_config_impl const> cfg_;
449   449  
450   detail::workspace ws_; 450   detail::workspace ws_;
451   static_request m_; 451   static_request m_;
452   std::uint64_t body_limit_; 452   std::uint64_t body_limit_;
453   std::uint64_t body_total_; 453   std::uint64_t body_total_;
454   std::uint64_t payload_remain_; 454   std::uint64_t payload_remain_;
455   std::uint64_t chunk_remain_; 455   std::uint64_t chunk_remain_;
456   std::size_t body_avail_; 456   std::size_t body_avail_;
457   std::size_t nprepare_; 457   std::size_t nprepare_;
458   458  
459   detail::flat_buffer fb_; 459   detail::flat_buffer fb_;
460   detail::circular_buffer cb0_; 460   detail::circular_buffer cb0_;
461   detail::circular_buffer cb1_; 461   detail::circular_buffer cb1_;
462   462  
463   std::array<capy::mutable_buffer, 2> mbp_; 463   std::array<capy::mutable_buffer, 2> mbp_;
464   std::array<capy::const_buffer, 2> cbp_; 464   std::array<capy::const_buffer, 2> cbp_;
465   465  
466   std::unique_ptr<detail::filter> filter_; 466   std::unique_ptr<detail::filter> filter_;
467   467  
468   state state_; 468   state state_;
469   bool got_header_; 469   bool got_header_;
470   bool got_eof_; 470   bool got_eof_;
471   bool head_response_; 471   bool head_response_;
472   bool needs_chunk_close_; 472   bool needs_chunk_close_;
473   bool trailer_headers_; 473   bool trailer_headers_;
474   bool chunked_body_ended; 474   bool chunked_body_ended;
475   475  
476   public: 476   public:
HITCBC 477   2181 impl(std::shared_ptr<parser_config_impl const> cfg, detail::kind k) 477   2181 impl(std::shared_ptr<parser_config_impl const> cfg, detail::kind k)
HITCBC 478   2181 : cfg_(std::move(cfg)) 478   2181 : cfg_(std::move(cfg))
HITCBC 479   2181 , ws_(cfg_->space_needed) 479   2181 , ws_(cfg_->space_needed)
HITCBC 480   2181 , m_(ws_.data(), ws_.size()) 480   2181 , m_(ws_.data(), ws_.size())
HITCBC 481   2181 , state_(state::reset) 481   2181 , state_(state::reset)
HITCBC 482   2181 , got_header_(false) 482   2181 , got_header_(false)
483   { 483   {
HITCBC 484   2181 m_.h_ = detail::header(detail::empty{ k }); 484   2181 m_.h_ = detail::header(detail::empty{ k });
HITCBC 485   2181 } 485   2181 }
486   486  
487   bool 487   bool
HITCBC 488   36139 got_header() const noexcept 488   36139 got_header() const noexcept
489   { 489   {
HITCBC 490   36139 return got_header_; 490   36139 return got_header_;
491   } 491   }
492   492  
493   bool 493   bool
HITCBC 494   59150 is_complete() const noexcept 494   59150 is_complete() const noexcept
495   { 495   {
HITCBC 496   59150 return state_ == state::complete; 496   59150 return state_ == state::complete;
497   } 497   }
498   498  
499   static_request const& 499   static_request const&
HITCBC 500   316 safe_get_request() const 500   316 safe_get_request() const
501   { 501   {
502   // headers must be received 502   // headers must be received
HITCBC 503   316 if(! got_header_) 503   316 if(! got_header_)
MISUBC 504   ✗ detail::throw_logic_error(); 504   ✗ detail::throw_logic_error();
505   505  
HITCBC 506   316 return m_; 506   316 return m_;
507   } 507   }
508   508  
509   static_response const& 509   static_response const&
HITCBC 510   3 safe_get_response() const 510   3 safe_get_response() const
511   { 511   {
512   // headers must be received 512   // headers must be received
HITCBC 513   3 if(! got_header_) 513   3 if(! got_header_)
MISUBC 514   ✗ detail::throw_logic_error(); 514   ✗ detail::throw_logic_error();
515   515  
516   // TODO: use a union 516   // TODO: use a union
HITCBC 517   3 return reinterpret_cast<static_response const&>(m_); 517   3 return reinterpret_cast<static_response const&>(m_);
518   } 518   }
519   519  
520   void 520   void
HITCBC 521   2728 reset() noexcept 521   2728 reset() noexcept
522   { 522   {
HITCBC 523   2728 ws_.clear(); 523   2728 ws_.clear();
HITCBC 524   2728 state_ = state::start; 524   2728 state_ = state::start;
HITCBC 525   2728 got_header_ = false; 525   2728 got_header_ = false;
HITCBC 526   2728 got_eof_ = false; 526   2728 got_eof_ = false;
HITCBC 527   2728 } 527   2728 }
528   528  
529   void 529   void
HITCBC 530   10657 start( 530   10657 start(
531   bool head_response) 531   bool head_response)
532   { 532   {
HITCBC 533   10657 std::size_t leftover = 0; 533   10657 std::size_t leftover = 0;
HITCBC 534   10657 switch(state_) 534   10657 switch(state_)
535   { 535   {
HITCBC 536   1 default: 536   1 default:
537   case state::reset: 537   case state::reset:
538   // reset must be called first 538   // reset must be called first
HITCBC 539   1 detail::throw_logic_error(); 539   1 detail::throw_logic_error();
540   540  
HITCBC 541   2653 case state::start: 541   2653 case state::start:
542   // reset required on eof 542   // reset required on eof
HITCBC 543   2653 if(got_eof_) 543   2653 if(got_eof_)
MISUBC 544   ✗ detail::throw_logic_error(); 544   ✗ detail::throw_logic_error();
HITCBC 545   2653 break; 545   2653 break;
546   546  
HITCBC 547   3 case state::header: 547   3 case state::header:
HITCBC 548   3 if(fb_.size() == 0) 548   3 if(fb_.size() == 0)
549   { 549   {
550   // start() called twice 550   // start() called twice
HITCBC 551   2 detail::throw_logic_error(); 551   2 detail::throw_logic_error();
552   } 552   }
553   BOOST_FALLTHROUGH; 553   BOOST_FALLTHROUGH;
554   554  
555   case state::header_done: 555   case state::header_done:
556   case state::body: 556   case state::body:
557   // current message is incomplete 557   // current message is incomplete
HITCBC 558   2 detail::throw_logic_error(); 558   2 detail::throw_logic_error();
559   559  
HITCBC 560   7999 case state::complete: 560   7999 case state::complete:
561   { 561   {
562   // remove available body. 562   // remove available body.
HITCBC 563   7999 if(is_plain()) 563   7999 if(is_plain())
HITCBC 564   4000 cb0_.consume(body_avail_); 564   4000 cb0_.consume(body_avail_);
565   // move leftovers to front 565   // move leftovers to front
566   566  
HITCBC 567   7999 ws_.clear(); 567   7999 ws_.clear();
HITCBC 568   7999 leftover = cb0_.size(); 568   7999 leftover = cb0_.size();
569   569  
HITCBC 570   7999 auto* dest = reinterpret_cast<char*>(ws_.data()); 570   7999 auto* dest = reinterpret_cast<char*>(ws_.data());
HITCBC 571   7999 auto cbp = cb0_.data(); 571   7999 auto cbp = cb0_.data();
HITCBC 572   7999 auto* a = static_cast<char const*>(cbp[0].data()); 572   7999 auto* a = static_cast<char const*>(cbp[0].data());
HITCBC 573   7999 auto* b = static_cast<char const*>(cbp[1].data()); 573   7999 auto* b = static_cast<char const*>(cbp[1].data());
HITCBC 574   7999 auto an = cbp[0].size(); 574   7999 auto an = cbp[0].size();
HITCBC 575   7999 auto bn = cbp[1].size(); 575   7999 auto bn = cbp[1].size();
576   576  
HITCBC 577   7999 if(bn == 0) 577   7999 if(bn == 0)
578   { 578   {
HITCBC 579   7561 std::memmove(dest, a, an); 579   7561 std::memmove(dest, a, an);
580   } 580   }
581   else 581   else
582   { 582   {
583   // if `a` can fit between `dest` and `b`, shift `b` to the left 583   // if `a` can fit between `dest` and `b`, shift `b` to the left
584   // and copy `a` to its position. if `a` fits perfectly, the 584   // and copy `a` to its position. if `a` fits perfectly, the
585   // shift will be of size 0. 585   // shift will be of size 0.
586   // if `a` requires more space, shift `b` to the right and 586   // if `a` requires more space, shift `b` to the right and
587   // copy `a` to its position. this process may require multiple 587   // copy `a` to its position. this process may require multiple
588   // iterations and should be done chunk by chunk to prevent `b` 588   // iterations and should be done chunk by chunk to prevent `b`
589   // from overlapping with `a`. 589   // from overlapping with `a`.
590   do 590   do
591   { 591   {
592   // clamp right shifts to prevent overlap with `a` 592   // clamp right shifts to prevent overlap with `a`
HITCBC 593   438 auto* bp = (std::min)(dest + an, const_cast<char*>(a) - bn); 593   438 auto* bp = (std::min)(dest + an, const_cast<char*>(a) - bn);
HITCBC 594   438 b = static_cast<char const*>(std::memmove(bp, b, bn)); 594   438 b = static_cast<char const*>(std::memmove(bp, b, bn));
595   595  
596   // a chunk or all of `a` based on available space 596   // a chunk or all of `a` based on available space
HITCBC 597   438 auto chunk_a = static_cast<std::size_t>(b - dest); 597   438 auto chunk_a = static_cast<std::size_t>(b - dest);
HITCBC 598   438 std::memcpy(dest, a, chunk_a); // never overlap 598   438 std::memcpy(dest, a, chunk_a); // never overlap
HITCBC 599   438 an -= chunk_a; 599   438 an -= chunk_a;
HITCBC 600   438 dest += chunk_a; 600   438 dest += chunk_a;
HITCBC 601   438 a += chunk_a; 601   438 a += chunk_a;
HITCBC 602   438 } while(an); 602   438 } while(an);
603   } 603   }
604   604  
HITCBC 605   7999 break; 605   7999 break;
606   } 606   }
607   } 607   }
608   608  
HITCBC 609   10652 ws_.clear(); 609   10652 ws_.clear();
610   610  
HITCBC 611   21304 fb_ = { 611   21304 fb_ = {
HITCBC 612   10652 ws_.data(), 612   10652 ws_.data(),
HITCBC 613   10652 cfg_->headers.max_size + cfg_->min_buffer, 613   10652 cfg_->headers.max_size + cfg_->min_buffer,
614   leftover }; 614   leftover };
615   615  
HITCBC 616   10652 BOOST_ASSERT( 616   10652 BOOST_ASSERT(
617   fb_.capacity() == cfg_->max_overread() - leftover); 617   fb_.capacity() == cfg_->max_overread() - leftover);
618   618  
HITCBC 619   10652 BOOST_ASSERT( 619   10652 BOOST_ASSERT(
620   head_response == false || 620   head_response == false ||
621   m_.h_.kind == detail::kind::response); 621   m_.h_.kind == detail::kind::response);
622   622  
HITCBC 623   10652 m_.h_ = detail::header(detail::empty{m_.h_.kind}); 623   10652 m_.h_ = detail::header(detail::empty{m_.h_.kind});
HITCBC 624   10652 m_.h_.buf = reinterpret_cast<char*>(ws_.data()); 624   10652 m_.h_.buf = reinterpret_cast<char*>(ws_.data());
HITCBC 625   10652 m_.h_.cbuf = m_.h_.buf; 625   10652 m_.h_.cbuf = m_.h_.buf;
HITCBC 626   10652 m_.h_.cap = ws_.size(); 626   10652 m_.h_.cap = ws_.size();
627   627  
HITCBC 628   10652 state_ = state::header; 628   10652 state_ = state::header;
629   629  
630   // reset to the configured default 630   // reset to the configured default
HITCBC 631   10652 body_limit_ = cfg_->body_limit; 631   10652 body_limit_ = cfg_->body_limit;
632   632  
HITCBC 633   10652 body_total_ = 0; 633   10652 body_total_ = 0;
HITCBC 634   10652 payload_remain_ = 0; 634   10652 payload_remain_ = 0;
HITCBC 635   10652 chunk_remain_ = 0; 635   10652 chunk_remain_ = 0;
HITCBC 636   10652 body_avail_ = 0; 636   10652 body_avail_ = 0;
HITCBC 637   10652 nprepare_ = 0; 637   10652 nprepare_ = 0;
638   638  
HITCBC 639   10652 filter_.reset(); 639   10652 filter_.reset();
640   640  
HITCBC 641   10652 got_header_ = false; 641   10652 got_header_ = false;
HITCBC 642   10652 head_response_ = head_response; 642   10652 head_response_ = head_response;
HITCBC 643   10652 needs_chunk_close_ = false; 643   10652 needs_chunk_close_ = false;
HITCBC 644   10652 trailer_headers_ = false; 644   10652 trailer_headers_ = false;
HITCBC 645   10652 chunked_body_ended = false; 645   10652 chunked_body_ended = false;
HITCBC 646   10652 } 646   10652 }
647   647  
648   auto 648   auto
HITCBC 649   81921 prepare() -> 649   81921 prepare() ->
650   mutable_buffers_type 650   mutable_buffers_type
651   { 651   {
HITCBC 652   81921 nprepare_ = 0; 652   81921 nprepare_ = 0;
653   653  
HITCBC 654   81921 switch(state_) 654   81921 switch(state_)
655   { 655   {
HITCBC 656   1 default: 656   1 default:
657   case state::reset: 657   case state::reset:
658   // reset must be called first 658   // reset must be called first
HITCBC 659   1 detail::throw_logic_error(); 659   1 detail::throw_logic_error();
660   660  
HITCBC 661   1 case state::start: 661   1 case state::start:
662   // start must be called first 662   // start must be called first
HITCBC 663   1 detail::throw_logic_error(); 663   1 detail::throw_logic_error();
664   664  
HITCBC 665   39834 case state::header: 665   39834 case state::header:
666   { 666   {
HITCBC 667   39834 BOOST_ASSERT( 667   39834 BOOST_ASSERT(
668   m_.h_.size < cfg_->headers.max_size); 668   m_.h_.size < cfg_->headers.max_size);
HITCBC 669   39834 std::size_t n = fb_.capacity(); 669   39834 std::size_t n = fb_.capacity();
HITCBC 670   39834 BOOST_ASSERT(n <= cfg_->max_overread()); 670   39834 BOOST_ASSERT(n <= cfg_->max_overread());
HITCBC 671   39834 n = clamp(n, cfg_->max_prepare); 671   39834 n = clamp(n, cfg_->max_prepare);
HITCBC 672   39834 mbp_[0] = fb_.prepare(n); 672   39834 mbp_[0] = fb_.prepare(n);
HITCBC 673   39834 nprepare_ = n; 673   39834 nprepare_ = n;
HITCBC 674   39834 return mutable_buffers_type(&mbp_[0], 1); 674   39834 return mutable_buffers_type(&mbp_[0], 1);
675   } 675   }
676   676  
MISUBC 677   ✗ case state::header_done: 677   ✗ case state::header_done:
678   // forgot to call parse() 678   // forgot to call parse()
MISUBC 679   ✗ detail::throw_logic_error(); 679   ✗ detail::throw_logic_error();
680   680  
HITCBC 681   42084 case state::body: 681   42084 case state::body:
682   { 682   {
HITCBC 683   42084 if(got_eof_) 683   42084 if(got_eof_)
684   { 684   {
685   // forgot to call parse() 685   // forgot to call parse()
MISUBC 686   ✗ detail::throw_logic_error(); 686   ✗ detail::throw_logic_error();
687   } 687   }
688   688  
HITCBC 689   42084 if(! is_plain()) 689   42084 if(! is_plain())
690   { 690   {
691   // buffered payload 691   // buffered payload
HITCBC 692   22017 std::size_t n = cb0_.capacity(); 692   22017 std::size_t n = cb0_.capacity();
HITCBC 693   22017 n = clamp(n, cfg_->max_prepare); 693   22017 n = clamp(n, cfg_->max_prepare);
HITCBC 694   22017 nprepare_ = n; 694   22017 nprepare_ = n;
HITCBC 695   22017 mbp_ = cb0_.prepare(n); 695   22017 mbp_ = cb0_.prepare(n);
HITCBC 696   22017 return detail::make_span(mbp_); 696   22017 return detail::make_span(mbp_);
697   } 697   }
698   else 698   else
699   { 699   {
700   // plain payload 700   // plain payload
HITCBC 701   20067 std::size_t n = cb0_.capacity(); 701   20067 std::size_t n = cb0_.capacity();
HITCBC 702   20067 n = clamp(n, cfg_->max_prepare); 702   20067 n = clamp(n, cfg_->max_prepare);
703   703  
HITCBC 704   20067 if(m_.payload() == payload::size) 704   20067 if(m_.payload() == payload::size)
705   { 705   {
HITCBC 706   20053 if(n > payload_remain_) 706   20053 if(n > payload_remain_)
707   { 707   {
HITCBC 708   18836 std::size_t overread = 708   18836 std::size_t overread =
HITCBC 709   18836 n - static_cast<std::size_t>(payload_remain_); 709   18836 n - static_cast<std::size_t>(payload_remain_);
HITCBC 710   18836 if(overread > cfg_->max_overread()) 710   18836 if(overread > cfg_->max_overread())
HITCBC 711   8920 n = static_cast<std::size_t>(payload_remain_) + 711   8920 n = static_cast<std::size_t>(payload_remain_) +
HITCBC 712   8920 cfg_->max_overread(); 712   8920 cfg_->max_overread();
713   } 713   }
714   } 714   }
715   else 715   else
716   { 716   {
HITCBC 717   14 BOOST_ASSERT( 717   14 BOOST_ASSERT(
718   m_.payload() == payload::to_eof); 718   m_.payload() == payload::to_eof);
719   // No more messages can be pipelined, so 719   // No more messages can be pipelined, so
720   // limit the output buffer to the remaining 720   // limit the output buffer to the remaining
721   // body limit plus one byte to detect 721   // body limit plus one byte to detect
722   // exhaustion. 722   // exhaustion.
HITCBC 723   14 std::uint64_t r = body_limit_remain(); 723   14 std::uint64_t r = body_limit_remain();
HITCBC 724   14 if(r != std::uint64_t(-1)) 724   14 if(r != std::uint64_t(-1))
HITCBC 725   14 r += 1; 725   14 r += 1;
HITCBC 726   14 n = clamp(r, n); 726   14 n = clamp(r, n);
727   } 727   }
728   728  
HITCBC 729   20067 nprepare_ = n; 729   20067 nprepare_ = n;
HITCBC 730   20067 mbp_ = cb0_.prepare(n); 730   20067 mbp_ = cb0_.prepare(n);
HITCBC 731   20067 return detail::make_span(mbp_); 731   20067 return detail::make_span(mbp_);
732   } 732   }
733   } 733   }
734   734  
HITCBC 735   1 case state::complete: 735   1 case state::complete:
736   // already complete 736   // already complete
HITCBC 737   1 detail::throw_logic_error(); 737   1 detail::throw_logic_error();
738   } 738   }
739   } 739   }
740   740  
741   void 741   void
HITCBC 742   80860 commit( 742   80860 commit(
743   std::size_t n) 743   std::size_t n)
744   { 744   {
HITCBC 745   80860 switch(state_) 745   80860 switch(state_)
746   { 746   {
HITCBC 747   1 default: 747   1 default:
748   case state::reset: 748   case state::reset:
749   { 749   {
750   // reset must be called first 750   // reset must be called first
HITCBC 751   1 detail::throw_logic_error(); 751   1 detail::throw_logic_error();
752   } 752   }
753   753  
HITCBC 754   1 case state::start: 754   1 case state::start:
755   { 755   {
756   // forgot to call start() 756   // forgot to call start()
HITCBC 757   1 detail::throw_logic_error(); 757   1 detail::throw_logic_error();
758   } 758   }
759   759  
HITCBC 760   39048 case state::header: 760   39048 case state::header:
761   { 761   {
HITCBC 762   39048 if(n > nprepare_) 762   39048 if(n > nprepare_)
763   { 763   {
764   // n can't be greater than size of 764   // n can't be greater than size of
765   // the buffers returned by prepare() 765   // the buffers returned by prepare()
HITCBC 766   1 detail::throw_invalid_argument(); 766   1 detail::throw_invalid_argument();
767   } 767   }
768   768  
HITCBC 769   39047 if(got_eof_) 769   39047 if(got_eof_)
770   { 770   {
771   // can't commit after EOF 771   // can't commit after EOF
HITCBC 772   1 detail::throw_logic_error(); 772   1 detail::throw_logic_error();
773   } 773   }
774   774  
HITCBC 775   39046 nprepare_ = 0; // invalidate 775   39046 nprepare_ = 0; // invalidate
HITCBC 776   39046 fb_.commit(n); 776   39046 fb_.commit(n);
HITCBC 777   39046 break; 777   39046 break;
778   } 778   }
779   779  
MISUBC 780   ✗ case state::header_done: 780   ✗ case state::header_done:
781   { 781   {
782   // forgot to call parse() 782   // forgot to call parse()
MISUBC 783   ✗ detail::throw_logic_error(); 783   ✗ detail::throw_logic_error();
784   } 784   }
785   785  
HITCBC 786   41810 case state::body: 786   41810 case state::body:
787   { 787   {
HITCBC 788   41810 if(n > nprepare_) 788   41810 if(n > nprepare_)
789   { 789   {
790   // n can't be greater than size of 790   // n can't be greater than size of
791   // the buffers returned by prepare() 791   // the buffers returned by prepare()
HITCBC 792   2 detail::throw_invalid_argument(); 792   2 detail::throw_invalid_argument();
793   } 793   }
794   794  
HITCBC 795   41808 if(got_eof_) 795   41808 if(got_eof_)
796   { 796   {
797   // can't commit after EOF 797   // can't commit after EOF
MISUBC 798   ✗ detail::throw_logic_error(); 798   ✗ detail::throw_logic_error();
799   } 799   }
800   800  
HITCBC 801   41808 nprepare_ = 0; // invalidate 801   41808 nprepare_ = 0; // invalidate
HITCBC 802   41808 cb0_.commit(n); 802   41808 cb0_.commit(n);
HITCBC 803   41808 break; 803   41808 break;
804   } 804   }
805   805  
MISUBC 806   ✗ case state::complete: 806   ✗ case state::complete:
807   { 807   {
808   // already complete 808   // already complete
MISUBC 809   ✗ detail::throw_logic_error(); 809   ✗ detail::throw_logic_error();
810   } 810   }
811   } 811   }
HITCBC 812   80854 } 812   80854 }
813   813  
814   void 814   void
HITCBC 815   134 commit_eof() 815   134 commit_eof()
816   { 816   {
HITCBC 817   134 nprepare_ = 0; // invalidate 817   134 nprepare_ = 0; // invalidate
818   818  
HITCBC 819   134 switch(state_) 819   134 switch(state_)
820   { 820   {
HITCBC 821   1 default: 821   1 default:
822   case state::reset: 822   case state::reset:
823   // reset must be called first 823   // reset must be called first
HITCBC 824   1 detail::throw_logic_error(); 824   1 detail::throw_logic_error();
825   825  
HITCBC 826   1 case state::start: 826   1 case state::start:
827   // forgot to call start() 827   // forgot to call start()
HITCBC 828   1 detail::throw_logic_error(); 828   1 detail::throw_logic_error();
829   829  
HITCBC 830   14 case state::header: 830   14 case state::header:
HITCBC 831   14 got_eof_ = true; 831   14 got_eof_ = true;
HITCBC 832   14 break; 832   14 break;
833   833  
MISUBC 834   ✗ case state::header_done: 834   ✗ case state::header_done:
835   // forgot to call parse() 835   // forgot to call parse()
MISUBC 836   ✗ detail::throw_logic_error(); 836   ✗ detail::throw_logic_error();
837   837  
HITCBC 838   117 case state::body: 838   117 case state::body:
HITCBC 839   117 got_eof_ = true; 839   117 got_eof_ = true;
HITCBC 840   117 break; 840   117 break;
841   841  
HITCBC 842   1 case state::complete: 842   1 case state::complete:
843   // can't commit eof when complete 843   // can't commit eof when complete
HITCBC 844   1 detail::throw_logic_error(); 844   1 detail::throw_logic_error();
845   } 845   }
HITCBC 846   131 } 846   131 }
847   847  
848   void 848   void
HITCBC 849   98779 parse( 849   98779 parse(
850   std::error_code& ec) 850   std::error_code& ec)
851   { 851   {
HITCBC 852   98779 ec = {}; 852   98779 ec = {};
HITCBC 853   98779 switch(state_) 853   98779 switch(state_)
854   { 854   {
HITCBC 855   1 default: 855   1 default:
856   case state::reset: 856   case state::reset:
857   // reset must be called first 857   // reset must be called first
HITCBC 858   1 detail::throw_logic_error(); 858   1 detail::throw_logic_error();
859   859  
HITCBC 860   1 case state::start: 860   1 case state::start:
861   // start must be called first 861   // start must be called first
HITCBC 862   1 detail::throw_logic_error(); 862   1 detail::throw_logic_error();
863   863  
HITCBC 864   45037 case state::header: 864   45037 case state::header:
865   { 865   {
HITCBC 866   45037 BOOST_ASSERT(m_.h_.buf == static_cast< 866   45037 BOOST_ASSERT(m_.h_.buf == static_cast<
867   void const*>(ws_.data())); 867   void const*>(ws_.data()));
HITCBC 868   45037 BOOST_ASSERT(m_.h_.cbuf == static_cast< 868   45037 BOOST_ASSERT(m_.h_.cbuf == static_cast<
869   void const*>(ws_.data())); 869   void const*>(ws_.data()));
870   870  
HITCBC 871   45037 m_.h_.parse(fb_.size(), cfg_->headers, ec); 871   45037 m_.h_.parse(fb_.size(), cfg_->headers, ec);
872   872  
HITCBC 873   45037 if(ec == condition::need_more_input) 873   45037 if(ec == condition::need_more_input)
874   { 874   {
HITCBC 875   35191 if(! got_eof_) 875   35191 if(! got_eof_)
876   { 876   {
877   // headers incomplete 877   // headers incomplete
HITCBC 878   35180 return; 878   35180 return;
879   } 879   }
880   880  
HITCBC 881   11 if(fb_.size() == 0) 881   11 if(fb_.size() == 0)
882   { 882   {
883   // stream closed cleanly 883   // stream closed cleanly
HITCBC 884   6 state_ = state::reset; 884   6 state_ = state::reset;
HITCBC 885   6 ec = error::end_of_stream; 885   6 ec = error::end_of_stream;
HITCBC 886   6 return; 886   6 return;
887   } 887   }
888   888  
889   // stream closed with a 889   // stream closed with a
890   // partial message received 890   // partial message received
HITCBC 891   5 state_ = state::reset; 891   5 state_ = state::reset;
HITCBC 892   5 ec = error::incomplete; 892   5 ec = error::incomplete;
HITCBC 893   5 return; 893   5 return;
894   } 894   }
HITCBC 895   9846 else if(ec) 895   9846 else if(ec)
896   { 896   {
897   // other error, 897   // other error,
898   // 898   //
899   // VFALCO map this to a bad 899   // VFALCO map this to a bad
900   // request or bad response error? 900   // request or bad response error?
901   // 901   //
HITCBC 902   259 state_ = state::reset; // unrecoverable 902   259 state_ = state::reset; // unrecoverable
HITCBC 903   259 return; 903   259 return;
904   } 904   }
905   905  
HITCBC 906   9587 got_header_ = true; 906   9587 got_header_ = true;
907   907  
908   // reserve headers + table 908   // reserve headers + table
HITCBC 909   9587 ws_.reserve_front(m_.h_.size); 909   9587 ws_.reserve_front(m_.h_.size);
HITCBC 910   9587 ws_.reserve_back(m_.h_.table_space()); 910   9587 ws_.reserve_back(m_.h_.table_space());
911   911  
912   // no payload 912   // no payload
HITCBC 913   18366 if(m_.payload() == payload::none || 913   18366 if(m_.payload() == payload::none ||
HITCBC 914   8779 head_response_) 914   8779 head_response_)
915   { 915   {
916   // octets of the next message 916   // octets of the next message
HITCBC 917   808 auto overread = fb_.size() - m_.h_.size; 917   808 auto overread = fb_.size() - m_.h_.size;
HITCBC 918   808 cb0_ = { ws_.data(), overread, overread }; 918   808 cb0_ = { ws_.data(), overread, overread };
HITCBC 919   808 ws_.reserve_front(overread); 919   808 ws_.reserve_front(overread);
HITCBC 920   808 state_ = state::complete; 920   808 state_ = state::complete;
HITCBC 921   808 return; 921   808 return;
922   } 922   }
923   923  
HITCBC 924   8779 state_ = state::header_done; 924   8779 state_ = state::header_done;
HITCBC 925   8779 break; 925   8779 break;
926   } 926   }
927   927  
HITCBC 928   8776 case state::header_done: 928   8776 case state::header_done:
929   { 929   {
930   // metadata error 930   // metadata error
HITCBC 931   8776 if(m_.payload() == payload::error) 931   8776 if(m_.payload() == payload::error)
932   { 932   {
933   // VFALCO This needs looking at 933   // VFALCO This needs looking at
HITCBC 934   60 ec = error::bad_payload; 934   60 ec = error::bad_payload;
HITCBC 935   60 state_ = state::reset; // unrecoverable 935   60 state_ = state::reset; // unrecoverable
HITCBC 936   60 return; 936   60 return;
937   } 937   }
938   938  
939   // overread currently includes any and all octets that 939   // overread currently includes any and all octets that
940   // extend beyond the current end of the header 940   // extend beyond the current end of the header
941   // this can include associated body octets for the 941   // this can include associated body octets for the
942   // current message or octets of the next message in the 942   // current message or octets of the next message in the
943   // stream, e.g. pipelining is being used 943   // stream, e.g. pipelining is being used
HITCBC 944   8716 auto const overread = fb_.size() - m_.h_.size; 944   8716 auto const overread = fb_.size() - m_.h_.size;
HITCBC 945   8716 BOOST_ASSERT(overread <= cfg_->max_overread()); 945   8716 BOOST_ASSERT(overread <= cfg_->max_overread());
946   946  
HITCBC 947   8716 auto cap = fb_.capacity() + overread + 947   8716 auto cap = fb_.capacity() + overread +
HITCBC 948   8716 cfg_->min_buffer; 948   8716 cfg_->min_buffer;
949   949  
950   // reserve body buffers first, as the decoder 950   // reserve body buffers first, as the decoder
951   // must be installed after them. 951   // must be installed after them.
HITCBC 952   8716 auto const p = ws_.reserve_front(cap); 952   8716 auto const p = ws_.reserve_front(cap);
953   953  
954   // Content-Encoding 954   // Content-Encoding
HITCBC 955   8716 switch(m_.metadata().content_encoding.coding) 955   8716 switch(m_.metadata().content_encoding.coding)
956   { 956   {
MISUBC 957   ✗ case content_coding::deflate: 957   ✗ case content_coding::deflate:
MISUBC 958   ✗ if(!cfg_->apply_deflate_decoder) 958   ✗ if(!cfg_->apply_deflate_decoder)
MISUBC 959   ✗ goto no_filter; 959   ✗ goto no_filter;
MISUBC 960   ✗ if(auto* svc = capy::get_system_context().find_service<http::zlib::inflate_service>()) 960   ✗ if(auto* svc = capy::get_system_context().find_service<http::zlib::inflate_service>())
961   { 961   {
MISUBC 962   ✗ filter_.reset(new zlib_filter( 962   ✗ filter_.reset(new zlib_filter(
963   *svc, 963   *svc,
MISUBC 964   ✗ cfg_->zlib_window_bits)); 964   ✗ cfg_->zlib_window_bits));
965   } 965   }
MISUBC 966   ✗ break; 966   ✗ break;
967   967  
MISUBC 968   ✗ case content_coding::gzip: 968   ✗ case content_coding::gzip:
MISUBC 969   ✗ if(!cfg_->apply_gzip_decoder) 969   ✗ if(!cfg_->apply_gzip_decoder)
MISUBC 970   ✗ goto no_filter; 970   ✗ goto no_filter;
MISUBC 971   ✗ if(auto* svc = capy::get_system_context().find_service<http::zlib::inflate_service>()) 971   ✗ if(auto* svc = capy::get_system_context().find_service<http::zlib::inflate_service>())
972   { 972   {
MISUBC 973   ✗ filter_.reset(new zlib_filter( 973   ✗ filter_.reset(new zlib_filter(
974   *svc, 974   *svc,
MISUBC 975   ✗ cfg_->zlib_window_bits + 16)); 975   ✗ cfg_->zlib_window_bits + 16));
976   } 976   }
MISUBC 977   ✗ break; 977   ✗ break;
978   978  
MISUBC 979   ✗ case content_coding::br: 979   ✗ case content_coding::br:
MISUBC 980   ✗ if(!cfg_->apply_brotli_decoder) 980   ✗ if(!cfg_->apply_brotli_decoder)
MISUBC 981   ✗ goto no_filter; 981   ✗ goto no_filter;
MISUBC 982   ✗ if(auto* svc = capy::get_system_context().find_service<http::brotli::decode_service>()) 982   ✗ if(auto* svc = capy::get_system_context().find_service<http::brotli::decode_service>())
983   { 983   {
MISUBC 984   ✗ filter_.reset(new brotli_filter(*svc)); 984   ✗ filter_.reset(new brotli_filter(*svc));
985   } 985   }
MISUBC 986   ✗ break; 986   ✗ break;
987   987  
MISUBC 988   ✗ no_filter: 988   ✗ no_filter:
HITCBC 989   8716 default: 989   8716 default:
HITCBC 990   8716 break; 990   8716 break;
991   } 991   }
992   992  
HITCBC 993   8716 if(is_plain()) 993   8716 if(is_plain())
994   { 994   {
HITCBC 995   4387 cb0_ = { p, cap, overread }; 995   4387 cb0_ = { p, cap, overread };
HITCBC 996   4387 cb1_ = {}; 996   4387 cb1_ = {};
997   } 997   }
998   else 998   else
999   { 999   {
1000   // buffered payload 1000   // buffered payload
HITCBC 1001   4329 std::size_t n0 = (overread > cfg_->min_buffer) 1001   4329 std::size_t n0 = (overread > cfg_->min_buffer)
HITCBC 1002   8658 ? overread 1002   8658 ? overread
HITCBC 1003   4329 : cfg_->min_buffer; 1003   4329 : cfg_->min_buffer;
HITCBC 1004   4329 std::size_t n1 = cfg_->min_buffer; 1004   4329 std::size_t n1 = cfg_->min_buffer;
1005   1005  
HITCBC 1006   4329 cb0_ = { p , n0, overread }; 1006   4329 cb0_ = { p , n0, overread };
HITCBC 1007   4329 cb1_ = { p + n0 , n1 }; 1007   4329 cb1_ = { p + n0 , n1 };
1008   } 1008   }
1009   1009  
HITCBC 1010   8716 if(m_.payload() == payload::size) 1010   8716 if(m_.payload() == payload::size)
1011   { 1011   {
HITCBC 1012   8540 if(!filter_ && 1012   8540 if(!filter_ &&
HITCBC 1013   4270 body_limit_ < m_.payload_size()) 1013   4270 body_limit_ < m_.payload_size())
1014   { 1014   {
HITCBC 1015   3 ec = error::body_too_large; 1015   3 ec = error::body_too_large;
HITCBC 1016   3 state_ = state::reset; 1016   3 state_ = state::reset;
HITCBC 1017   3 return; 1017   3 return;
1018   } 1018   }
HITCBC 1019   4267 payload_remain_ = m_.payload_size(); 1019   4267 payload_remain_ = m_.payload_size();
1020   } 1020   }
1021   1021  
HITCBC 1022   8713 state_ = state::body; 1022   8713 state_ = state::body;
1023   BOOST_FALLTHROUGH; 1023   BOOST_FALLTHROUGH;
1024   } 1024   }
1025   1025  
HITCBC 1026   51464 case state::body: 1026   51464 case state::body:
1027   { 1027   {
HITCBC 1028   51464 BOOST_ASSERT(state_ == state::body); 1028   51464 BOOST_ASSERT(state_ == state::body);
HITCBC 1029   51464 BOOST_ASSERT(m_.payload() != payload::none); 1029   51464 BOOST_ASSERT(m_.payload() != payload::none);
HITCBC 1030   51464 BOOST_ASSERT(m_.payload() != payload::error); 1030   51464 BOOST_ASSERT(m_.payload() != payload::error);
1031   1031  
HITCBC 1032   8366 auto set_state_to_complete = [&]() 1032   8366 auto set_state_to_complete = [&]()
1033   { 1033   {
HITCBC 1034   8366 state_ = state::complete; 1034   8366 state_ = state::complete;
HITCBC 1035   59830 }; 1035   59830 };
1036   1036  
HITCBC 1037   51464 if(m_.payload() == payload::chunked) 1037   51464 if(m_.payload() == payload::chunked)
1038   { 1038   {
1039   for(;;) 1039   for(;;)
1040   { 1040   {
HITCBC 1041   78651 if(chunk_remain_ == 0 1041   78651 if(chunk_remain_ == 0
HITCBC 1042   75748 && !chunked_body_ended) 1042   75748 && !chunked_body_ended)
1043   { 1043   {
HITCBC 1044   71617 auto cs = chained_sequence(cb0_.data()); 1044   71617 auto cs = chained_sequence(cb0_.data());
HITCBC 1045   20849 auto check_ec = [&]() 1045   20849 auto check_ec = [&]()
1046   { 1046   {
HITCBC 1047   20849 if(ec == condition::need_more_input && got_eof_) 1047   20849 if(ec == condition::need_more_input && got_eof_)
1048   { 1048   {
MISUBC 1049   ✗ ec = error::incomplete; 1049   ✗ ec = error::incomplete;
MISUBC 1050   ✗ state_ = state::reset; 1050   ✗ state_ = state::reset;
1051   } 1051   }
HITCBC 1052   92466 }; 1052   92466 };
1053   1053  
HITCBC 1054   71617 if(needs_chunk_close_) 1054   71617 if(needs_chunk_close_)
1055   { 1055   {
HITCBC 1056   62239 parse_eol(cs, ec); 1056   62239 parse_eol(cs, ec);
HITCBC 1057   62239 if(ec) 1057   62239 if(ec)
1058   { 1058   {
HITCBC 1059   435 check_ec(); 1059   435 check_ec();
HITCBC 1060   20849 return; 1060   20849 return;
1061   } 1061   }
1062   } 1062   }
HITCBC 1063   9378 else if(trailer_headers_) 1063   9378 else if(trailer_headers_)
1064   { 1064   {
HITCBC 1065   4243 skip_trailer_headers(cs, ec); 1065   4243 skip_trailer_headers(cs, ec);
HITCBC 1066   4243 if(ec) 1066   4243 if(ec)
1067   { 1067   {
HITCBC 1068   112 check_ec(); 1068   112 check_ec();
HITCBC 1069   112 return; 1069   112 return;
1070   } 1070   }
HITCBC 1071   4131 cb0_.consume(cb0_.size() - cs.size()); 1071   4131 cb0_.consume(cb0_.size() - cs.size());
HITCBC 1072   4131 chunked_body_ended = true; 1072   4131 chunked_body_ended = true;
HITCBC 1073   8276 continue; 1073   8276 continue;
1074   } 1074   }
1075   1075  
HITCBC 1076   66939 auto chunk_size = parse_hex(cs, ec); 1076   66939 auto chunk_size = parse_hex(cs, ec);
HITCBC 1077   66939 if(ec) 1077   66939 if(ec)
1078   { 1078   {
HITCBC 1079   19950 check_ec(); 1079   19950 check_ec();
HITCBC 1080   19950 return; 1080   19950 return;
1081   } 1081   }
1082   1082  
1083   // skip chunk extensions 1083   // skip chunk extensions
HITCBC 1084   46989 find_eol(cs, ec); 1084   46989 find_eol(cs, ec);
HITCBC 1085   46989 if(ec) 1085   46989 if(ec)
1086   { 1086   {
HITCBC 1087   352 check_ec(); 1087   352 check_ec();
HITCBC 1088   352 return; 1088   352 return;
1089   } 1089   }
1090   1090  
HITCBC 1091   46637 cb0_.consume(cb0_.size() - cs.size()); 1091   46637 cb0_.consume(cb0_.size() - cs.size());
HITCBC 1092   46637 chunk_remain_ = chunk_size; 1092   46637 chunk_remain_ = chunk_size;
1093   1093  
HITCBC 1094   46637 needs_chunk_close_ = true; 1094   46637 needs_chunk_close_ = true;
HITCBC 1095   46637 if(chunk_remain_ == 0) 1095   46637 if(chunk_remain_ == 0)
1096   { 1096   {
HITCBC 1097   4145 needs_chunk_close_ = false; 1097   4145 needs_chunk_close_ = false;
HITCBC 1098   4145 trailer_headers_ = true; 1098   4145 trailer_headers_ = true;
HITCBC 1099   4145 continue; 1099   4145 continue;
1100   } 1100   }
1101   } 1101   }
1102   1102  
HITCBC 1103   49526 if(cb0_.size() == 0 && !chunked_body_ended) 1103   49526 if(cb0_.size() == 0 && !chunked_body_ended)
1104   { 1104   {
HITCBC 1105   1830 if(got_eof_) 1105   1830 if(got_eof_)
1106   { 1106   {
HITCBC 1107   1 ec = error::incomplete; 1107   1 ec = error::incomplete;
HITCBC 1108   1 state_ = state::reset; 1108   1 state_ = state::reset;
HITCBC 1109   1 return; 1109   1 return;
1110   } 1110   }
1111   1111  
HITCBC 1112   1829 ec = error::need_data; 1112   1829 ec = error::need_data;
HITCBC 1113   1829 return; 1113   1829 return;
1114   } 1114   }
1115   1115  
HITCBC 1116   47696 if(filter_) 1116   47696 if(filter_)
1117   { 1117   {
MISUBC 1118   ✗ chunk_remain_ -= apply_filter( 1118   ✗ chunk_remain_ -= apply_filter(
1119   ec, 1119   ec,
1120   clamp(chunk_remain_, cb0_.size()), 1120   clamp(chunk_remain_, cb0_.size()),
MISUBC 1121   ✗ !chunked_body_ended); 1121   ✗ !chunked_body_ended);
1122   1122  
MISUBC 1123   ✗ if(ec || chunked_body_ended) 1123   ✗ if(ec || chunked_body_ended)
MISUBC 1124   ✗ return; 1124   ✗ return;
1125   } 1125   }
1126   else 1126   else
1127   { 1127   {
1128   const std::size_t chunk_avail = 1128   const std::size_t chunk_avail =
HITCBC 1129   47696 clamp(chunk_remain_, cb0_.size()); 1129   47696 clamp(chunk_remain_, cb0_.size());
1130   1130  
HITCBC 1131   47696 if(body_limit_remain() < chunk_avail) 1131   47696 if(body_limit_remain() < chunk_avail)
1132   { 1132   {
MISUBC 1133   ✗ ec = error::body_too_large; 1133   ✗ ec = error::body_too_large;
MISUBC 1134   ✗ state_ = state::reset; 1134   ✗ state_ = state::reset;
MISUBC 1135   ✗ return; 1135   ✗ return;
1136   } 1136   }
1137   1137  
1138   // in_place style 1138   // in_place style
HITCBC 1139   47696 auto copied = capy::buffer_copy( 1139   47696 auto copied = capy::buffer_copy(
HITCBC 1140   47696 cb1_.prepare(cb1_.capacity()), 1140   47696 cb1_.prepare(cb1_.capacity()),
HITCBC 1141   47696 cb0_.data(), 1141   47696 cb0_.data(),
1142   chunk_avail); 1142   chunk_avail);
HITCBC 1143   47696 chunk_remain_ -= copied; 1143   47696 chunk_remain_ -= copied;
HITCBC 1144   47696 body_avail_ += copied; 1144   47696 body_avail_ += copied;
HITCBC 1145   47696 body_total_ += copied; 1145   47696 body_total_ += copied;
HITCBC 1146   47696 cb0_.consume(copied); 1146   47696 cb0_.consume(copied);
HITCBC 1147   47696 cb1_.commit(copied); 1147   47696 cb1_.commit(copied);
HITCBC 1148   47696 if(cb1_.capacity() == 0 1148   47696 if(cb1_.capacity() == 0
HITCBC 1149   47696 && !chunked_body_ended) 1149   47696 && !chunked_body_ended)
1150   { 1150   {
MISUBC 1151   ✗ ec = error::in_place_overflow; 1151   ✗ ec = error::in_place_overflow;
MISUBC 1152   ✗ return; 1152   ✗ return;
1153   } 1153   }
1154   1154  
HITCBC 1155   47696 if(chunked_body_ended) 1155   47696 if(chunked_body_ended)
1156   { 1156   {
HITCBC 1157   4131 set_state_to_complete(); 1157   4131 set_state_to_complete();
HITCBC 1158   4131 return; 1158   4131 return;
1159   } 1159   }
1160   } 1160   }
HITCBC 1161   51841 } 1161   51841 }
1162   } 1162   }
1163   else 1163   else
1164   { 1164   {
1165   // non-chunked payload 1165   // non-chunked payload
1166   1166  
HITCBC 1167   73962 const std::size_t payload_avail = [&]() 1167   73962 const std::size_t payload_avail = [&]()
1168   { 1168   {
HITCBC 1169   24654 auto ret = cb0_.size(); 1169   24654 auto ret = cb0_.size();
HITCBC 1170   24654 if(!filter_) 1170   24654 if(!filter_)
HITCBC 1171   24654 ret -= body_avail_; 1171   24654 ret -= body_avail_;
HITCBC 1172   24654 if(m_.payload() == payload::size) 1172   24654 if(m_.payload() == payload::size)
HITCBC 1173   24397 return clamp(payload_remain_, ret); 1173   24397 return clamp(payload_remain_, ret);
1174   // payload::eof 1174   // payload::eof
HITCBC 1175   257 return ret; 1175   257 return ret;
HITCBC 1176   24654 }(); 1176   24654 }();
1177   1177  
HITCBC 1178   73962 const bool is_complete = [&]() 1178   73962 const bool is_complete = [&]()
1179   { 1179   {
HITCBC 1180   24654 if(m_.payload() == payload::size) 1180   24654 if(m_.payload() == payload::size)
HITCBC 1181   24397 return payload_avail == payload_remain_; 1181   24397 return payload_avail == payload_remain_;
1182   // payload::eof 1182   // payload::eof
HITCBC 1183   257 return got_eof_; 1183   257 return got_eof_;
HITCBC 1184   24654 }(); 1184   24654 }();
1185   1185  
HITCBC 1186   24654 if(filter_) 1186   24654 if(filter_)
1187   { 1187   {
MISUBC 1188   ✗ payload_remain_ -= apply_filter( 1188   ✗ payload_remain_ -= apply_filter(
MISUBC 1189   ✗ ec, payload_avail, !is_complete); 1189   ✗ ec, payload_avail, !is_complete);
MISUBC 1190   ✗ if(ec || is_complete) 1190   ✗ if(ec || is_complete)
MISUBC 1191   ✗ return; 1191   ✗ return;
1192   } 1192   }
1193   else 1193   else
1194   { 1194   {
1195   // plain body 1195   // plain body
1196   1196  
HITCBC 1197   24654 if(m_.payload() == payload::to_eof) 1197   24654 if(m_.payload() == payload::to_eof)
1198   { 1198   {
HITCBC 1199   257 if(body_limit_remain() < payload_avail) 1199   257 if(body_limit_remain() < payload_avail)
1200   { 1200   {
HITCBC 1201   1 ec = error::body_too_large; 1201   1 ec = error::body_too_large;
HITCBC 1202   1 state_ = state::reset; 1202   1 state_ = state::reset;
HITCBC 1203   1 return; 1203   1 return;
1204   } 1204   }
1205   } 1205   }
1206   1206  
1207   // in_place style 1207   // in_place style
HITCBC 1208   24653 payload_remain_ -= payload_avail; 1208   24653 payload_remain_ -= payload_avail;
HITCBC 1209   24653 body_avail_ += payload_avail; 1209   24653 body_avail_ += payload_avail;
HITCBC 1210   24653 body_total_ += payload_avail; 1210   24653 body_total_ += payload_avail;
HITCBC 1211   24653 if(cb0_.capacity() == 0 && !is_complete) 1211   24653 if(cb0_.capacity() == 0 && !is_complete)
1212   { 1212   {
HITCBC 1213   7 ec = error::in_place_overflow; 1213   7 ec = error::in_place_overflow;
HITCBC 1214   7 return; 1214   7 return;
1215   } 1215   }
1216   1216  
HITCBC 1217   24646 if(is_complete) 1217   24646 if(is_complete)
1218   { 1218   {
HITCBC 1219   4235 set_state_to_complete(); 1219   4235 set_state_to_complete();
HITCBC 1220   4235 return; 1220   4235 return;
1221   } 1221   }
1222   } 1222   }
1223   1223  
HITCBC 1224   20411 if(m_.payload() == payload::size && got_eof_) 1224   20411 if(m_.payload() == payload::size && got_eof_)
1225   { 1225   {
HITCBC 1226   1 ec = error::incomplete; 1226   1 ec = error::incomplete;
HITCBC 1227   1 state_ = state::reset; 1227   1 state_ = state::reset;
HITCBC 1228   1 return; 1228   1 return;
1229   } 1229   }
1230   1230  
HITCBC 1231   20410 ec = error::need_data; 1231   20410 ec = error::need_data;
HITCBC 1232   20410 return; 1232   20410 return;
1233   } 1233   }
1234   1234  
1235   break; 1235   break;
1236   } 1236   }
1237   1237  
HITCBC 1238   2213 case state::complete: 1238   2213 case state::complete:
HITCBC 1239   2213 break; 1239   2213 break;
1240   } 1240   }
1241   } 1241   }
1242   1242  
1243   auto 1243   auto
HITCBC 1244   41630 pull_body() -> 1244   41630 pull_body() ->
1245   const_buffers_type 1245   const_buffers_type
1246   { 1246   {
HITCBC 1247   41630 switch(state_) 1247   41630 switch(state_)
1248   { 1248   {
HITCBC 1249   30 case state::header_done: 1249   30 case state::header_done:
HITCBC 1250   30 return {}; 1250   30 return {};
HITCBC 1251   41598 case state::body: 1251   41598 case state::body:
1252   case state::complete: 1252   case state::complete:
HITCBC 1253   41598 cbp_ = prefix_pair( 1253   41598 cbp_ = prefix_pair(
HITCBC 1254   41598 (is_plain() ? cb0_ : cb1_).data(), 1254   41598 (is_plain() ? cb0_ : cb1_).data(),
1255   body_avail_); 1255   body_avail_);
HITCBC 1256   41598 return detail::make_span(cbp_); 1256   41598 return detail::make_span(cbp_);
HITCBC 1257   2 case state::reset: 1257   2 case state::reset:
HITCBC 1258   2 if(got_header_) 1258   2 if(got_header_)
HITCBC 1259   2 return {}; 1259   2 return {};
1260   BOOST_FALLTHROUGH; 1260   BOOST_FALLTHROUGH;
1261   default: 1261   default:
MISUBC 1262   ✗ detail::throw_logic_error(); 1262   ✗ detail::throw_logic_error();
1263   } 1263   }
1264   } 1264   }
1265   1265  
1266   void 1266   void
HITCBC 1267   39610 consume_body(std::size_t n) 1267   39610 consume_body(std::size_t n)
1268   { 1268   {
HITCBC 1269   39610 switch(state_) 1269   39610 switch(state_)
1270   { 1270   {
MISUBC 1271   ✗ case state::header_done: 1271   ✗ case state::header_done:
MISUBC 1272   ✗ return; 1272   ✗ return;
HITCBC 1273   39610 case state::body: 1273   39610 case state::body:
1274   case state::complete: 1274   case state::complete:
HITCBC 1275   39610 n = clamp(n, body_avail_); 1275   39610 n = clamp(n, body_avail_);
HITCBC 1276   39610 (is_plain() ? cb0_ : cb1_).consume(n); 1276   39610 (is_plain() ? cb0_ : cb1_).consume(n);
HITCBC 1277   39610 body_avail_ -= n; 1277   39610 body_avail_ -= n;
HITCBC 1278   39610 return; 1278   39610 return;
MISUBC 1279   ✗ case state::reset: 1279   ✗ case state::reset:
MISUBC 1280   ✗ if(got_header_) 1280   ✗ if(got_header_)
MISUBC 1281   ✗ return; 1281   ✗ return;
1282   BOOST_FALLTHROUGH; 1282   BOOST_FALLTHROUGH;
1283   default: 1283   default:
MISUBC 1284   ✗ detail::throw_logic_error(); 1284   ✗ detail::throw_logic_error();
1285   } 1285   }
1286   } 1286   }
1287   1287  
1288   core::string_view 1288   core::string_view
HITCBC 1289   712 body() const 1289   712 body() const
1290   { 1290   {
1291   // Precondition violation 1291   // Precondition violation
HITCBC 1292   712 if(state_ != state::complete) 1292   712 if(state_ != state::complete)
MISUBC 1293   ✗ detail::throw_logic_error(); 1293   ✗ detail::throw_logic_error();
1294   1294  
1295   // Precondition violation 1295   // Precondition violation
HITCBC 1296   712 if(body_avail_ != body_total_) 1296   712 if(body_avail_ != body_total_)
MISUBC 1297   ✗ detail::throw_logic_error(); 1297   ✗ detail::throw_logic_error();
1298   1298  
HITCBC 1299   712 auto cbp = (is_plain() ? cb0_ : cb1_).data(); 1299   712 auto cbp = (is_plain() ? cb0_ : cb1_).data();
HITCBC 1300   712 BOOST_ASSERT(body_avail_ <= cbp[0].size()); 1300   712 BOOST_ASSERT(body_avail_ <= cbp[0].size());
HITCBC 1301   712 return core::string_view( 1301   712 return core::string_view(
HITCBC 1302   712 static_cast<char const*>(cbp[0].data()), 1302   712 static_cast<char const*>(cbp[0].data()),
HITCBC 1303   1424 body_avail_); 1303   1424 body_avail_);
1304   } 1304   }
1305   1305  
1306   bool 1306   bool
HITCBC 1307   9 has_buffered_data() const noexcept 1307   9 has_buffered_data() const noexcept
1308   { 1308   {
HITCBC 1309   9 if(state_ != state::complete) 1309   9 if(state_ != state::complete)
HITCBC 1310   1 return false; 1310   1 return false;
1311   1311  
HITCBC 1312   8 if(is_plain()) 1312   8 if(is_plain())
HITCBC 1313   6 return cb0_.size() > body_avail_; 1313   6 return cb0_.size() > body_avail_;
HITCBC 1314   2 return cb0_.size() > 0; 1314   2 return cb0_.size() > 0;
1315   } 1315   }
1316   1316  
1317   void 1317   void
HITCBC 1318   5 set_body_limit(std::uint64_t n) 1318   5 set_body_limit(std::uint64_t n)
1319   { 1319   {
HITCBC 1320   5 switch(state_) 1320   5 switch(state_)
1321   { 1321   {
HITCBC 1322   1 case state::header: 1322   1 case state::header:
1323   case state::header_done: 1323   case state::header_done:
HITCBC 1324   1 body_limit_ = n; 1324   1 body_limit_ = n;
HITCBC 1325   1 break; 1325   1 break;
HITCBC 1326   2 case state::complete: 1326   2 case state::complete:
1327   // only allowed for empty bodies 1327   // only allowed for empty bodies
HITCBC 1328   2 if(body_total_ == 0) 1328   2 if(body_total_ == 0)
HITCBC 1329   1 break; 1329   1 break;
1330   BOOST_FALLTHROUGH; 1330   BOOST_FALLTHROUGH;
1331   default: 1331   default:
1332   // set body_limit before parsing the body 1332   // set body_limit before parsing the body
HITCBC 1333   3 detail::throw_logic_error(); 1333   3 detail::throw_logic_error();
1334   } 1334   }
HITCBC 1335   2 } 1335   2 }
1336   1336  
1337   private: 1337   private:
1338   bool 1338   bool
HITCBC 1339   140727 is_plain() const noexcept 1339   140727 is_plain() const noexcept
1340   { 1340   {
HITCBC 1341   281454 return ! filter_ && 1341   281454 return ! filter_ &&
HITCBC 1342   281454 m_.payload() != payload::chunked; 1342   281454 m_.payload() != payload::chunked;
1343   } 1343   }
1344   1344  
1345   std::uint64_t 1345   std::uint64_t
HITCBC 1346   47967 body_limit_remain() const noexcept 1346   47967 body_limit_remain() const noexcept
1347   { 1347   {
HITCBC 1348   47967 return body_limit_ - body_total_; 1348   47967 return body_limit_ - body_total_;
1349   } 1349   }
1350   1350  
1351   std::size_t 1351   std::size_t
MISUBC 1352   ✗ apply_filter( 1352   ✗ apply_filter(
1353   std::error_code& ec, 1353   std::error_code& ec,
1354   std::size_t payload_avail, 1354   std::size_t payload_avail,
1355   bool more) 1355   bool more)
1356   { 1356   {
MISUBC 1357   ✗ std::size_t p0 = payload_avail; 1357   ✗ std::size_t p0 = payload_avail;
1358   for(;;) 1358   for(;;)
1359   { 1359   {
MISUBC 1360   ✗ if(payload_avail == 0 && more) 1360   ✗ if(payload_avail == 0 && more)
MISUBC 1361   ✗ break; 1361   ✗ break;
1362   1362  
MISUBC 1363   ✗ auto f_rs = [&](){ 1363   ✗ auto f_rs = [&](){
MISUBC 1364   ✗ BOOST_ASSERT(filter_ != nullptr); 1364   ✗ BOOST_ASSERT(filter_ != nullptr);
MISUBC 1365   ✗ std::size_t n = clamp(body_limit_remain()); 1365   ✗ std::size_t n = clamp(body_limit_remain());
MISUBC 1366   ✗ n = clamp(n, cb1_.capacity()); 1366   ✗ n = clamp(n, cb1_.capacity());
1367   1367  
MISUBC 1368   ✗ return filter_->process( 1368   ✗ return filter_->process(
MISUBC 1369   ✗ detail::make_span(cb1_.prepare(n)), 1369   ✗ detail::make_span(cb1_.prepare(n)),
MISUBC 1370   ✗ prefix_pair(cb0_.data(), payload_avail), 1370   ✗ prefix_pair(cb0_.data(), payload_avail),
MISUBC 1371   ✗ more); 1371   ✗ more);
MISUBC 1372   ✗ }(); 1372   ✗ }();
1373   1373  
MISUBC 1374   ✗ cb0_.consume(f_rs.in_bytes); 1374   ✗ cb0_.consume(f_rs.in_bytes);
MISUBC 1375   ✗ payload_avail -= f_rs.in_bytes; 1375   ✗ payload_avail -= f_rs.in_bytes;
MISUBC 1376   ✗ body_total_ += f_rs.out_bytes; 1376   ✗ body_total_ += f_rs.out_bytes;
1377   1377  
1378   // in_place style 1378   // in_place style
MISUBC 1379   ✗ cb1_.commit(f_rs.out_bytes); 1379   ✗ cb1_.commit(f_rs.out_bytes);
MISUBC 1380   ✗ body_avail_ += f_rs.out_bytes; 1380   ✗ body_avail_ += f_rs.out_bytes;
MISUBC 1381   ✗ if(cb1_.capacity() == 0 && 1381   ✗ if(cb1_.capacity() == 0 &&
MISUBC 1382   ✗ !f_rs.finished && f_rs.in_bytes == 0) 1382   ✗ !f_rs.finished && f_rs.in_bytes == 0)
1383   { 1383   {
MISUBC 1384   ✗ ec = error::in_place_overflow; 1384   ✗ ec = error::in_place_overflow;
MISUBC 1385   ✗ goto done; 1385   ✗ goto done;
1386   } 1386   }
1387   1387  
MISUBC 1388   ✗ if(f_rs.ec) 1388   ✗ if(f_rs.ec)
1389   { 1389   {
MISUBC 1390   ✗ ec = f_rs.ec; 1390   ✗ ec = f_rs.ec;
MISUBC 1391   ✗ state_ = state::reset; 1391   ✗ state_ = state::reset;
MISUBC 1392   ✗ break; 1392   ✗ break;
1393   } 1393   }
1394   1394  
MISUBC 1395   ✗ if(body_limit_remain() == 0 && 1395   ✗ if(body_limit_remain() == 0 &&
MISUBC 1396   ✗ !f_rs.finished && f_rs.in_bytes == 0) 1396   ✗ !f_rs.finished && f_rs.in_bytes == 0)
1397   { 1397   {
MISUBC 1398   ✗ ec = error::body_too_large; 1398   ✗ ec = error::body_too_large;
MISUBC 1399   ✗ state_ = state::reset; 1399   ✗ state_ = state::reset;
MISUBC 1400   ✗ break; 1400   ✗ break;
1401   } 1401   }
1402   1402  
MISUBC 1403   ✗ if(f_rs.finished) 1403   ✗ if(f_rs.finished)
1404   { 1404   {
MISUBC 1405   ✗ if(!more) 1405   ✗ if(!more)
MISUBC 1406   ✗ state_ = state::complete; 1406   ✗ state_ = state::complete;
MISUBC 1407   ✗ break; 1407   ✗ break;
1408   } 1408   }
MISUBC 1409   ✗ } 1409   ✗ }
1410   1410  
MISUBC 1411   ✗ done: 1411   ✗ done:
MISUBC 1412   ✗ return p0 - payload_avail; 1412   ✗ return p0 - payload_avail;
1413   } 1413   }
1414   }; 1414   };
1415   1415  
1416   //------------------------------------------------ 1416   //------------------------------------------------
1417   // 1417   //
1418   // Special Members 1418   // Special Members
1419   // 1419   //
1420   //------------------------------------------------ 1420   //------------------------------------------------
1421   1421  
HITCBC 1422   2196 parser:: 1422   2196 parser::
1423   ~parser() 1423   ~parser()
1424   { 1424   {
HITCBC 1425   2196 delete impl_; 1425   2196 delete impl_;
HITCBC 1426   2196 } 1426   2196 }
1427   1427  
HITCBC 1428   12 parser:: 1428   12 parser::
HITCBC 1429   12 parser() noexcept 1429   12 parser() noexcept
HITCBC 1430   12 : impl_(nullptr) 1430   12 : impl_(nullptr)
1431   { 1431   {
HITCBC 1432   12 } 1432   12 }
1433   1433  
HITCBC 1434   3 parser:: 1434   3 parser::
HITCBC 1435   3 parser(parser&& other) noexcept 1435   3 parser(parser&& other) noexcept
HITCBC 1436   3 : impl_(other.impl_) 1436   3 : impl_(other.impl_)
1437   { 1437   {
HITCBC 1438   3 other.impl_ = nullptr; 1438   3 other.impl_ = nullptr;
HITCBC 1439   3 } 1439   3 }
1440   1440  
HITCBC 1441   2181 parser:: 1441   2181 parser::
1442   parser( 1442   parser(
1443   std::shared_ptr<parser_config_impl const> cfg, 1443   std::shared_ptr<parser_config_impl const> cfg,
HITCBC 1444   2181 detail::kind k) 1444   2181 detail::kind k)
HITCBC 1445   2181 : impl_(new impl(std::move(cfg), k)) 1445   2181 : impl_(new impl(std::move(cfg), k))
1446   { 1446   {
1447   // TODO: use a single allocation for 1447   // TODO: use a single allocation for
1448   // impl and workspace buffer. 1448   // impl and workspace buffer.
HITCBC 1449   2181 } 1449   2181 }
1450   1450  
1451   void 1451   void
HITCBC 1452   4 parser:: 1452   4 parser::
1453   assign(parser&& other) noexcept 1453   assign(parser&& other) noexcept
1454   { 1454   {
HITCBC 1455   4 if(this == &other) 1455   4 if(this == &other)
MISUBC 1456   ✗ return; 1456   ✗ return;
HITCBC 1457   4 delete impl_; 1457   4 delete impl_;
HITCBC 1458   4 impl_ = other.impl_; 1458   4 impl_ = other.impl_;
HITCBC 1459   4 other.impl_ = nullptr; 1459   4 other.impl_ = nullptr;
1460   } 1460   }
1461   1461  
1462   //-------------------------------------------- 1462   //--------------------------------------------
1463   // 1463   //
1464   // Observers 1464   // Observers
1465   // 1465   //
1466   //-------------------------------------------- 1466   //--------------------------------------------
1467   1467  
1468   bool 1468   bool
HITCBC 1469   36139 parser::got_header() const noexcept 1469   36139 parser::got_header() const noexcept
1470   { 1470   {
HITCBC 1471   36139 BOOST_ASSERT(impl_); 1471   36139 BOOST_ASSERT(impl_);
HITCBC 1472   36139 return impl_->got_header(); 1472   36139 return impl_->got_header();
1473   } 1473   }
1474   1474  
1475   bool 1475   bool
HITCBC 1476   59150 parser::is_complete() const noexcept 1476   59150 parser::is_complete() const noexcept
1477   { 1477   {
HITCBC 1478   59150 BOOST_ASSERT(impl_); 1478   59150 BOOST_ASSERT(impl_);
HITCBC 1479   59150 return impl_->is_complete(); 1479   59150 return impl_->is_complete();
1480   } 1480   }
1481   1481  
1482   //------------------------------------------------ 1482   //------------------------------------------------
1483   // 1483   //
1484   // Modifiers 1484   // Modifiers
1485   // 1485   //
1486   //------------------------------------------------ 1486   //------------------------------------------------
1487   1487  
1488   void 1488   void
HITCBC 1489   2728 parser:: 1489   2728 parser::
1490   reset() noexcept 1490   reset() noexcept
1491   { 1491   {
HITCBC 1492   2728 BOOST_ASSERT(impl_); 1492   2728 BOOST_ASSERT(impl_);
HITCBC 1493   2728 impl_->reset(); 1493   2728 impl_->reset();
HITCBC 1494   2728 } 1494   2728 }
1495   1495  
1496   void 1496   void
HITCBC 1497   10657 parser::start() 1497   10657 parser::start()
1498   { 1498   {
HITCBC 1499   10657 BOOST_ASSERT(impl_); 1499   10657 BOOST_ASSERT(impl_);
HITCBC 1500   10657 impl_->start(false); 1500   10657 impl_->start(false);
HITCBC 1501   10652 } 1501   10652 }
1502   1502  
1503   auto 1503   auto
HITCBC 1504   81921 parser:: 1504   81921 parser::
1505   prepare() -> 1505   prepare() ->
1506   mutable_buffers_type 1506   mutable_buffers_type
1507   { 1507   {
HITCBC 1508   81921 BOOST_ASSERT(impl_); 1508   81921 BOOST_ASSERT(impl_);
HITCBC 1509   81921 return impl_->prepare(); 1509   81921 return impl_->prepare();
1510   } 1510   }
1511   1511  
1512   void 1512   void
HITCBC 1513   80860 parser:: 1513   80860 parser::
1514   commit( 1514   commit(
1515   std::size_t n) 1515   std::size_t n)
1516   { 1516   {
HITCBC 1517   80860 BOOST_ASSERT(impl_); 1517   80860 BOOST_ASSERT(impl_);
HITCBC 1518   80860 impl_->commit(n); 1518   80860 impl_->commit(n);
HITCBC 1519   80854 } 1519   80854 }
1520   1520  
1521   void 1521   void
HITCBC 1522   134 parser:: 1522   134 parser::
1523   commit_eof() 1523   commit_eof()
1524   { 1524   {
HITCBC 1525   134 BOOST_ASSERT(impl_); 1525   134 BOOST_ASSERT(impl_);
HITCBC 1526   134 impl_->commit_eof(); 1526   134 impl_->commit_eof();
HITCBC 1527   131 } 1527   131 }
1528   1528  
1529   void 1529   void
HITCBC 1530   98779 parser:: 1530   98779 parser::
1531   parse( 1531   parse(
1532   std::error_code& ec) 1532   std::error_code& ec)
1533   { 1533   {
HITCBC 1534   98779 BOOST_ASSERT(impl_); 1534   98779 BOOST_ASSERT(impl_);
HITCBC 1535   98779 impl_->parse(ec); 1535   98779 impl_->parse(ec);
HITCBC 1536   98777 } 1536   98777 }
1537   1537  
1538   auto 1538   auto
HITCBC 1539   41630 parser:: 1539   41630 parser::
1540   pull_body() -> 1540   pull_body() ->
1541   const_buffers_type 1541   const_buffers_type
1542   { 1542   {
HITCBC 1543   41630 BOOST_ASSERT(impl_); 1543   41630 BOOST_ASSERT(impl_);
HITCBC 1544   41630 return impl_->pull_body(); 1544   41630 return impl_->pull_body();
1545   } 1545   }
1546   1546  
1547   void 1547   void
HITCBC 1548   39610 parser:: 1548   39610 parser::
1549   consume_body(std::size_t n) 1549   consume_body(std::size_t n)
1550   { 1550   {
HITCBC 1551   39610 BOOST_ASSERT(impl_); 1551   39610 BOOST_ASSERT(impl_);
HITCBC 1552   39610 impl_->consume_body(n); 1552   39610 impl_->consume_body(n);
HITCBC 1553   39610 } 1553   39610 }
1554   1554  
1555   core::string_view 1555   core::string_view
HITCBC 1556   712 parser:: 1556   712 parser::
1557   body() const 1557   body() const
1558   { 1558   {
HITCBC 1559   712 BOOST_ASSERT(impl_); 1559   712 BOOST_ASSERT(impl_);
HITCBC 1560   712 return impl_->body(); 1560   712 return impl_->body();
1561   } 1561   }
1562   1562  
1563   core::string_view 1563   core::string_view
MISUBC 1564   ✗ parser:: 1564   ✗ parser::
1565   release_buffered_data() noexcept 1565   release_buffered_data() noexcept
1566   { 1566   {
1567   // TODO 1567   // TODO
MISUBC 1568   ✗ return {}; 1568   ✗ return {};
1569   } 1569   }
1570   1570  
1571   bool 1571   bool
HITCBC 1572   9 parser:: 1572   9 parser::
1573   has_buffered_data() const noexcept 1573   has_buffered_data() const noexcept
1574   { 1574   {
HITCBC 1575   9 BOOST_ASSERT(impl_); 1575   9 BOOST_ASSERT(impl_);
HITCBC 1576   9 return impl_->has_buffered_data(); 1576   9 return impl_->has_buffered_data();
1577   } 1577   }
1578   1578  
1579   void 1579   void
HITCBC 1580   5 parser:: 1580   5 parser::
1581   set_body_limit(std::uint64_t n) 1581   set_body_limit(std::uint64_t n)
1582   { 1582   {
HITCBC 1583   5 BOOST_ASSERT(impl_); 1583   5 BOOST_ASSERT(impl_);
HITCBC 1584   5 impl_->set_body_limit(n); 1584   5 impl_->set_body_limit(n);
HITCBC 1585   2 } 1585   2 }
1586   1586  
1587   //------------------------------------------------ 1587   //------------------------------------------------
1588   // 1588   //
1589   // Implementation 1589   // Implementation
1590   // 1590   //
1591   //------------------------------------------------ 1591   //------------------------------------------------
1592   1592  
1593   void 1593   void
MISUBC 1594   ✗ parser:: 1594   ✗ parser::
1595   start_impl(bool head_response) 1595   start_impl(bool head_response)
1596   { 1596   {
MISUBC 1597   ✗ BOOST_ASSERT(impl_); 1597   ✗ BOOST_ASSERT(impl_);
MISUBC 1598   ✗ impl_->start(head_response); 1598   ✗ impl_->start(head_response);
MISUBC 1599   ✗ } 1599   ✗ }
1600   1600  
1601   static_request const& 1601   static_request const&
HITCBC 1602   316 parser:: 1602   316 parser::
1603   safe_get_request() const 1603   safe_get_request() const
1604   { 1604   {
HITCBC 1605   316 BOOST_ASSERT(impl_); 1605   316 BOOST_ASSERT(impl_);
HITCBC 1606   316 return impl_->safe_get_request(); 1606   316 return impl_->safe_get_request();
1607   } 1607   }
1608   1608  
1609   static_response const& 1609   static_response const&
HITCBC 1610   3 parser:: 1610   3 parser::
1611   safe_get_response() const 1611   safe_get_response() const
1612   { 1612   {
HITCBC 1613   3 BOOST_ASSERT(impl_); 1613   3 BOOST_ASSERT(impl_);
HITCBC 1614   3 return impl_->safe_get_response(); 1614   3 return impl_->safe_get_response();
1615   } 1615   }
1616   1616  
1617   } // http 1617   } // http
1618   } // boost 1618   } // boost