Skip to content

Commit f8ffe20

Browse files
committed
add head containers and head_parser
1 parent ce7feab commit f8ffe20

47 files changed

Lines changed: 11052 additions & 262 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

example/usage.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ inspect_response(corosio::tls_context tls_ctx)
6868
if(ec)
6969
throw std::system_error(ec);
7070

71-
std::cout << "status: " << r.status_int() << '\n';
72-
std::cout << "reason: " << r.reason() << '\n';
73-
std::cout << "headers: " << r.headers() << '\n';
74-
std::cout << "body: " << co_await r.as<std::string>() << '\n';
71+
std::cout << "status: " << r.status_int() << '\n';
72+
std::cout << "reason: " << r.reason() << '\n';
73+
std::cout << "headers:\n" << r.headers();
74+
std::cout << "body: " << co_await r.as<std::string>() << '\n';
7575
// end::inspect_response[]
7676
}
7777

include/boost/burl.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,23 @@
1111
#define BOOST_BURL_HPP
1212

1313
#include <boost/burl/any_request_body.hpp>
14-
#include <boost/burl/conversion.hpp>
1514
#include <boost/burl/client.hpp>
15+
#include <boost/burl/conversion.hpp>
1616
#include <boost/burl/error.hpp>
17+
#include <boost/burl/fields.hpp>
18+
#include <boost/burl/fields_base.hpp>
1719
#include <boost/burl/file.hpp>
20+
#include <boost/burl/head_parser.hpp>
1821
#include <boost/burl/json.hpp>
22+
#include <boost/burl/message_head_base.hpp>
1923
#include <boost/burl/multipart_form.hpp>
2024
#include <boost/burl/request.hpp>
2125
#include <boost/burl/request_body.hpp>
26+
#include <boost/burl/request_head.hpp>
27+
#include <boost/burl/request_head_base.hpp>
2228
#include <boost/burl/response.hpp>
29+
#include <boost/burl/response_head.hpp>
30+
#include <boost/burl/response_head_base.hpp>
2331
#include <boost/burl/string.hpp>
2432
#include <boost/burl/urlencoded_form.hpp>
2533

include/boost/burl/client.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <boost/burl/cookie_jar.hpp>
1414
#include <boost/burl/detail/config.hpp>
1515
#include <boost/burl/detail/connection_pool.hpp>
16+
#include <boost/burl/fields.hpp>
1617
#include <boost/burl/request.hpp>
1718
#include <boost/burl/response.hpp>
1819

@@ -21,8 +22,6 @@
2122
#include <boost/capy/io_task.hpp>
2223
#include <boost/corosio/endpoint.hpp>
2324
#include <boost/corosio/tls_context.hpp>
24-
#include <boost/http/field.hpp>
25-
#include <boost/http/fields.hpp>
2625
#include <boost/url/url.hpp>
2726
#include <boost/url/url_view.hpp>
2827

@@ -315,7 +314,7 @@ class client
315314
private:
316315
config config_;
317316
std::shared_ptr<detail::connection_pool> pool_;
318-
http::fields headers_;
317+
fields headers_;
319318
burl::cookie_jar cookie_jar_;
320319

321320
public:
@@ -388,7 +387,7 @@ class client
388387
c.headers().set(http::field::user_agent, "BoostBurl/1.0");
389388
@endcode
390389
*/
391-
http::fields&
390+
fields_base&
392391
headers() noexcept
393392
{
394393
return headers_;
@@ -401,7 +400,7 @@ class client
401400
precedence over default headers with the
402401
same name.
403402
*/
404-
const http::fields&
403+
const fields_base&
405404
headers() const noexcept
406405
{
407406
return headers_;

include/boost/burl/detail/parser.hpp

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define BOOST_BURL_DETAIL_PARSER_HPP
1212

1313
#include <boost/burl/error.hpp>
14+
#include <boost/burl/head_parser.hpp>
1415
#include <boost/burl/detail/circular_buffer.hpp>
1516

1617
#include <boost/capy/buffers/buffer_copy.hpp>
@@ -19,10 +20,7 @@
1920
#include <boost/capy/io_task.hpp>
2021
#include <boost/capy/read.hpp>
2122
#include <boost/http/concept/buffer_source.hpp>
22-
#include <boost/http/message_base.hpp>
23-
#include <boost/http/header_limits.hpp>
24-
#include <boost/http/static_response.hpp>
25-
#include <boost/http/static_request.hpp>
23+
#include <boost/http/metadata.hpp>
2624

2725
#include <memory>
2826

@@ -56,7 +54,7 @@ class parser
5654

5755
struct config
5856
{
59-
http::header_limits hdr_limits;
57+
header_limits hdr_limits;
6058

6159
std::size_t in_buffer = 64 * 1024;
6260
std::size_t dec_buffer = 8 * 1024;
@@ -106,7 +104,7 @@ class parser
106104

107105
parser(
108106
config const& cfg,
109-
http::detail::kind kind,
107+
bool is_request,
110108
capy::any_read_stream stream = {});
111109

112110
parser(parser&& other) noexcept = default;
@@ -124,10 +122,10 @@ class parser
124122
void
125123
start(bool head);
126124

127-
http::static_response const&
125+
burl::response_head_base const&
128126
get_response() const;
129127

130-
http::static_request const&
128+
burl::request_head_base const&
131129
get_request() const;
132130

133131
private:
@@ -145,9 +143,6 @@ class parser
145143
std::size_t
146144
payload_rem() const noexcept;
147145

148-
std::size_t
149-
table_reserve() const noexcept;
150-
151146
capy::io_task<>
152147
refill();
153148

@@ -165,31 +160,20 @@ class parser
165160
do_read_some(
166161
std::span<capy::mutable_buffer const> buffers);
167162

168-
struct header_deleter
169-
{
170-
void
171-
operator()(
172-
http::detail::header* h) const noexcept
173-
{
174-
::operator delete(h);
175-
}
176-
};
177-
178-
using header_ptr = std::unique_ptr<
179-
http::detail::header, header_deleter>;
180-
181-
http::header_limits hdr_limits_;
182163
capy::any_read_stream stream_;
183-
header_ptr h_;
164+
std::unique_ptr<char[]> buf_;
165+
head_parser hp_;
184166
decoder * dec_ = nullptr;
185167
circular_buffer in_;
186168
circular_buffer out_;
187169
std::uint64_t chunk_rem_ = 0;
188170
std::uint64_t transferred_ = 0;
189171
std::uint64_t decoded_ = 0;
190172
std::uint64_t body_limit_ = 0;
173+
std::uint64_t payload_size_ = 0;
191174
std::error_code dec_err_;
192175
http::payload payload_ = http::payload::none;
176+
bool is_req_ = true;
193177
bool head_ = false;
194178
bool started_ = false;
195179
bool got_header_ = false;

include/boost/burl/detail/request_parser.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
#include <boost/burl/detail/parser.hpp>
1414

15-
#include <boost/http/static_request.hpp>
16-
1715
#include <utility>
1816

1917
namespace boost
@@ -33,7 +31,7 @@ class request_parser
3331
request_parser(
3432
config const& cfg,
3533
capy::any_read_stream stream = {})
36-
: parser(cfg, http::detail::kind::request, std::move(stream))
34+
: parser(cfg, true, std::move(stream))
3735
{
3836
}
3937

@@ -48,7 +46,7 @@ class request_parser
4846
parser::start(false);
4947
}
5048

51-
http::static_request const&
49+
burl::request_head_base const&
5250
get() const
5351
{
5452
return get_request();

include/boost/burl/detail/response_parser.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
#include <boost/burl/detail/parser.hpp>
1414

15-
#include <boost/http/static_response.hpp>
16-
1715
#include <utility>
1816

1917
namespace boost
@@ -33,7 +31,7 @@ class response_parser
3331
response_parser(
3432
config const& cfg,
3533
capy::any_read_stream stream = {})
36-
: parser(cfg, http::detail::kind::response, std::move(stream))
34+
: parser(cfg, false, std::move(stream))
3735
{
3836
}
3937

@@ -48,7 +46,7 @@ class response_parser
4846
parser::start(head);
4947
}
5048

51-
http::static_response const&
49+
burl::response_head_base const&
5250
get() const
5351
{
5452
return get_response();

0 commit comments

Comments
 (0)