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_RESPONSE_PARSER_HPP | ||
11 | #define BOOST_HTTP_PROTO_RESPONSE_PARSER_HPP | ||
12 | |||
13 | #include <boost/http_proto/detail/config.hpp> | ||
14 | #include <boost/http_proto/error.hpp> | ||
15 | #include <boost/http_proto/parser.hpp> | ||
16 | #include <boost/http_proto/response_view.hpp> | ||
17 | #include <boost/http_proto/status.hpp> | ||
18 | #include <cstddef> | ||
19 | |||
20 | namespace boost { | ||
21 | namespace http_proto { | ||
22 | |||
23 | class BOOST_SYMBOL_VISIBLE | ||
24 | response_parser | ||
25 | : public parser | ||
26 | { | ||
27 | public: | ||
28 | /** Configuration settings for parsing requests | ||
29 | */ | ||
30 | struct config : config_base | ||
31 | { | ||
32 | /** Constructor | ||
33 | */ | ||
34 | 7 | config() noexcept | |
35 | 7 | { | |
36 | 7 | body_limit = 1024 * 1024; | |
37 | 7 | } | |
38 | }; | ||
39 | |||
40 | /** Constructor | ||
41 | */ | ||
42 | BOOST_HTTP_PROTO_DECL | ||
43 | response_parser(); | ||
44 | |||
45 | /** Constructor | ||
46 | */ | ||
47 | template<class... Params> | ||
48 | explicit | ||
49 | 12 | response_parser( | |
50 | std::size_t extra_buffer_size, | ||
51 | Params&&... params) | ||
52 | : parser( | ||
53 | detail::kind::response, | ||
54 |
1/2✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | config{}) |
55 | { | ||
56 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
12 | this->apply_params( |
57 | std::forward<Params>(params)...); | ||
58 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
12 | construct(extra_buffer_size); |
59 | 12 | } | |
60 | |||
61 | /** Prepare for the next message on the stream. | ||
62 | */ | ||
63 | void | ||
64 | 1 | start() | |
65 | { | ||
66 | 1 | start_impl(false); | |
67 | 1 | } | |
68 | |||
69 | /** Prepare for the next message on the stream. | ||
70 | |||
71 | This informs the parser not to read a | ||
72 | payload for the next message, regardless | ||
73 | of the presence or absence of certain | ||
74 | fields such as Content-Length or a chunked | ||
75 | Transfer-Encoding. Depending on the request, | ||
76 | some responses do not carry a body. For | ||
77 | example, a 200 response to a CONNECT | ||
78 | request from a tunneling proxy, or a | ||
79 | response to a HEAD request. In these | ||
80 | cases, callers may use this function | ||
81 | inform the parser that no body is | ||
82 | expected. The parser will consider the | ||
83 | message complete after the header has | ||
84 | been received. | ||
85 | |||
86 | @par Preconditions | ||
87 | |||
88 | This function must called before any calls to parse | ||
89 | the current message. | ||
90 | |||
91 | @see | ||
92 | https://datatracker.ietf.org/doc/html/rfc7230#section-3.3 | ||
93 | */ | ||
94 | void | ||
95 | 1 | start_head_response() | |
96 | { | ||
97 | 1 | start_impl(true); | |
98 | 1 | } | |
99 | |||
100 | /** Return the parsed response headers. | ||
101 | */ | ||
102 | BOOST_HTTP_PROTO_DECL | ||
103 | response_view | ||
104 | get() const; | ||
105 | }; | ||
106 | |||
107 | } // http_proto | ||
108 | } // boost | ||
109 | |||
110 | #endif | ||
111 |