Skip to content
Merged

Work #28

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ One line to make a request.
cross-origin hops.
- **Content encodings** — transparent `gzip`, `deflate`, and `br` decoding
when the corresponding decode service is installed.
- **Cookies** — RFC 6265 jar with optional public-suffix validation (libpsl).
- **Cookies** — RFC 6265bis jar with optional public-suffix validation (libpsl).
- **Authentication** — Basic and Bearer, per client or per request.
- **Proxies** — `http`, `socks5`, with credentials.
- **Timeouts** — connect, per-I/O, and whole-operation, overridable per
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindLibpsl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# Official repository: https://github.com/cppalliance/beast2
# Official repository: https://github.com/cppalliance/burl
#

# Provides imported targets:
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/ROOT/pages/2.guide/2a.making-requests.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ configure the request and return the builder again, so calls chain:

[source,cpp]
----
auto r = co_await client.get("https://example.com/search")
auto [ec, r] = co_await client.get("https://example.com/search")
.query("q", "boost")
.header(http::field::accept, "application/json")
.timeout(std::chrono::seconds(10))
Expand Down
4 changes: 2 additions & 2 deletions doc/modules/ROOT/pages/2.guide/2e.headers.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ single request. It comes in two overloads:

[source,cpp]
----
auto r = co_await client.get("https://example.com")
auto [ec, r] = co_await client.get("https://example.com")
.header(http::field::accept_language, "en")
.header("X-Trace-Id", "abc123")
.send();
Expand All @@ -47,7 +47,7 @@ name on the client:
client.headers().set(http::field::accept, "application/json");

// this one request asks for XML instead
auto r = co_await client.get("https://example.com")
auto [ec, r] = co_await client.get("https://example.com")
.header(http::field::accept, "application/xml")
.send();
----
Expand Down
4 changes: 2 additions & 2 deletions doc/modules/ROOT/pages/2.guide/2f.query-parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ query string, percent-encoding both:

[source,cpp]
----
auto r = co_await client.get("https://example.com/search")
auto [ec, r] = co_await client.get("https://example.com/search")
.query("category", "shoes")
.query("color", "blue")
.send();
Expand Down Expand Up @@ -55,7 +55,7 @@ cpp:request_builder::query[] appends to whatever the URL already carries:

[source,cpp]
----
auto r = co_await client.get("https://example.com/search?category=shoes")
auto [ec, r] = co_await client.get("https://example.com/search?category=shoes")
.query("color", "blue")
.send();
// GET /search?category=shoes&color=blue
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/ROOT/pages/2.guide/2h.redirects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ auto [ec, r] = co_await client.get("https://example.com/old")
.followlocation(false)
.send();

std::cout << r.status_int() << '\n'; // e.g. 301
std::cout << r.status_int() << '\n'; // e.g. 301
std::cout << r.headers().value_or(http::field::location, "") << '\n';
----

Expand Down
4 changes: 2 additions & 2 deletions doc/modules/ROOT/pages/2.guide/2i.cookies.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ cfg.cookies = true;
burl::client client(co_await capy::this_coro::executor, tls_ctx, cfg);

// the cookie set here is stored, and returned on the next request to the host
co_await client.get("https://example.com/login").send();
auto r = co_await client.get("https://example.com/account").send();
auto [ec1, r1] = co_await client.get("https://example.com/login").send();
auto [ec2, r2] = co_await client.get("https://example.com/account").send();
----

== The Cookie Jar
Expand Down
9 changes: 5 additions & 4 deletions doc/modules/ROOT/pages/2.guide/2j.timeouts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ whole-operation timeout can be overridden per request.

| cpp:client::config[config::timeout]
| The whole operation, from connecting through receipt of the response
headers. Whatever time is left then bounds reading the body in place. Off by
default.
headers. Whatever time is left then bounds a whole-body read
(cpp:response::as[as<T>] or cpp:response::as_view[as_view]), but not the
streaming sources you drive yourself. Off by default.
|===

They address different failure modes and are meant to be combined. The connect
Expand All @@ -48,7 +49,7 @@ cpp:client::config[config::timeout] for one request:

[source,cpp]
----
auto r = co_await client.get("https://example.com/report")
auto [ec, r] = co_await client.get("https://example.com/report")
.timeout(std::chrono::seconds(3))
.send();
----
Expand All @@ -68,4 +69,4 @@ if(ec == capy::error::timeout)

* xref:2.guide/2d.error-handling.adoc[] — Timeouts among transport failures
* xref:2.guide/2k.connection-pool.adoc[] — The idle timeout, a separate setting
* xref:2.guide/2c.responses.adoc[] — Which body reads the timeout covers
* xref:2.guide/2c.responses.adoc[] — The body-reading methods in detail
2 changes: 1 addition & 1 deletion doc/modules/ROOT/pages/2.guide/2l.proxies.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cfg.proxy = urls::url("socks5h://user:pass@localhost:1080");
burl::client client(co_await capy::this_coro::executor, tls_ctx, cfg);

// established through the proxy
auto r = co_await client.get("https://example.com").send();
auto [ec, r] = co_await client.get("https://example.com").send();
----

== Supported Schemes
Expand Down
4 changes: 2 additions & 2 deletions doc/modules/ROOT/pages/2.guide/2n.extending.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cpp:RequestBody[] concept:

[source,cpp]
----
struct RequestBody
struct MyRequestBody
{
std::optional<std::string> content_type() const;
std::optional<std::uint64_t> content_length() const;
Expand Down Expand Up @@ -52,7 +52,7 @@ like any built-in:

[source,cpp]
----
auto r = co_await client.post("https://example.com/post")
auto [ec, r] = co_await client.post("https://example.com/post")
.body<nlohmann::json>({ { "user", "John" } })
.send();
----
Expand Down
19 changes: 9 additions & 10 deletions include/boost/burl/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,13 @@ class client
within this duration, from connection
establishment through receipt of the
response headers. The remaining time
also applies to reading the body with
@ref response::try_as_view and
@ref response::as_view. Can be
overridden per request with
then bounds a whole-body read with
@ref response::as or
@ref response::as_view (and their
`try_` forms), but not the streaming
sources @ref response::as_buffer_source
and @ref response::as_read_source. Can
be overridden per request with
@ref request_builder::timeout.
*/
std::optional<clock::duration> timeout;
Expand Down Expand Up @@ -395,9 +398,7 @@ class client

The jar stores cookies received in responses
and supplies them for subsequent requests
when @ref config::cookies is enabled. It can
be persisted and restored using its stream
operators.
when @ref config::cookies is enabled.
*/
burl::cookie_jar&
cookie_jar() noexcept
Expand All @@ -409,9 +410,7 @@ class client

The jar stores cookies received in responses
and supplies them for subsequent requests
when @ref config::cookies is enabled. It can
be persisted and restored using its stream
operators.
when @ref config::cookies is enabled.
*/
const burl::cookie_jar&
cookie_jar() const noexcept
Expand Down
10 changes: 5 additions & 5 deletions include/boost/burl/cookie.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/beast2
// Official repository: https://github.com/cppalliance/burl
//

#ifndef BOOST_BURL_COOKIE_HPP
Expand Down Expand Up @@ -32,8 +32,8 @@ namespace burl
stored in a @ref cookie_jar.

@par Specification
@li <a href="https://datatracker.ietf.org/doc/html/rfc6265"
>HTTP State Management Mechanism (rfc6265)</a>
@li <a href="https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis"
>Cookies: HTTP State Management Mechanism (rfc6265bis)</a>

@see
@ref parse_cookie,
Expand Down Expand Up @@ -143,8 +143,8 @@ struct cookie
@endcode

@par Specification
@li <a href="https://datatracker.ietf.org/doc/html/rfc6265#section-5.2"
>5.2. The Set-Cookie Header (rfc6265)</a>
@li <a href="https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis#section-5.6"
>5.6. The Set-Cookie Header Field (rfc6265bis)</a>

@param sv The string to parse.

Expand Down
6 changes: 3 additions & 3 deletions include/boost/burl/cookie_jar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/beast2
// Official repository: https://github.com/cppalliance/burl
//

#ifndef BOOST_BURL_COOKIE_JAR_HPP
Expand Down Expand Up @@ -44,7 +44,7 @@ namespace burl

burl::client c(co_await capy::this_coro::executor, tls_ctx, cfg);

auto r = co_await c.get("https://example.com/login").send();
auto [ec, r] = co_await c.get("https://example.com/login").send();

// Print the stored cookies in Netscape format
std::cout << c.cookie_jar().to_netscape();
Expand Down Expand Up @@ -125,7 +125,7 @@ class cookie_jar
by domain, path, and the `Secure` attribute,
and returned as `name=value` pairs separated
by `"; "`, ordered with longer paths first
(RFC 6265bis 5.4). Expired cookies encountered
(RFC 6265bis 5.8). Expired cookies encountered
during matching are removed from the jar.

@param url The URL of the request.
Expand Down
2 changes: 1 addition & 1 deletion include/boost/burl/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace burl

@par Example
@code
auto r = co_await c.put("https://example.com/put")
auto [ec, r] = co_await c.put("https://example.com/put")
.body<std::filesystem::path>("./report.log")
.send();
@endcode
Expand Down
2 changes: 1 addition & 1 deletion include/boost/burl/multipart_form.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace burl
form.file("attachment", "./crash_report.log");
form.text("priority", "high");

auto r = co_await c.post("https://example.com/post")
auto [ec, r] = co_await c.post("https://example.com/post")
.body(form)
.send();
@endcode
Expand Down
4 changes: 2 additions & 2 deletions include/boost/burl/request_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class request_builder

@par Example
@code
auto r = co_await c.get("https://example.com/get")
auto [ec, r] = co_await c.get("https://example.com/get")
.query("category", "shoes")
.query("color", "blue")
.send();
Expand Down Expand Up @@ -237,7 +237,7 @@ class request_builder

@par Example
@code
auto r = co_await c.post("https://example.com/post")
auto [ec, r] = co_await c.post("https://example.com/post")
.body(json::value({ "key", "value" }))
.send();
@endcode
Expand Down
4 changes: 2 additions & 2 deletions include/boost/burl/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace burl

@par Example
@code
auto r = co_await c.post(url)
auto [ec, r] = co_await c.post(url)
.body(std::string("payload"))
.send();
@endcode
Expand Down Expand Up @@ -77,7 +77,7 @@ tag_invoke(body_from_tag<std::string_view>, std::string_view body);

@par Example
@code
auto r = co_await c.post(url)
auto [ec, r] = co_await c.post(url)
.body("payload")
.send();
@endcode
Expand Down
4 changes: 2 additions & 2 deletions include/boost/burl/urlencoded_form.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace burl

@par Example
@code
auto r = co_await c.post("https://example.com/post")
auto [ec, r] = co_await c.post("https://example.com/post")
.body(burl::urlencoded_form()
.append("user", "John")
.append("lang", "En"))
Expand Down Expand Up @@ -101,7 +101,7 @@ class urlencoded_form
{ "user", "John" },
{ "lang", "En" } };

auto r = co_await c.post("https://example.com/post")
auto [ec, r] = co_await c.post("https://example.com/post")
.body<burl::urlencoded_form>(fields)
.send();
@endcode
Expand Down
2 changes: 1 addition & 1 deletion src/cookie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/beast2
// Official repository: https://github.com/cppalliance/burl
//

#include <boost/burl/cookie.hpp>
Expand Down
12 changes: 6 additions & 6 deletions src/cookie_jar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/beast2
// Official repository: https://github.com/cppalliance/burl
//

#include <boost/burl/cookie_jar.hpp>
Expand Down Expand Up @@ -57,7 +57,7 @@ domain_match(
bool
path_match(core::string_view r_path, core::string_view c_path) noexcept
{
// RFC 6265 5.1.4: an empty request path defaults to "/"
// RFC 6265bis 5.1.4: an empty request path defaults to "/"
if(r_path.empty())
r_path = "/";

Expand Down Expand Up @@ -208,13 +208,13 @@ cookie_jar::add(const urls::url_view& url, cookie c)
auto& c_domain = c.domain.value();
normalize_host(c_domain);

// RFC 6265 5.2.3: a leading dot in the Domain attribute is ignored
// RFC 6265bis 5.6.3: a leading dot in the Domain attribute is ignored
if(c_domain.starts_with('.'))
c_domain.erase(0, 1);

if(is_public_suffix(c_domain))
{
// RFC 6265 5.3 step 5: a public-suffix Domain is rejected, unless
// RFC 6265bis 5.7 step 9: a public-suffix Domain is rejected, unless
// it equals the request host, which makes the cookie host-only.
if(c_domain != r_host)
return;
Expand Down Expand Up @@ -277,7 +277,7 @@ cookie_jar::add(const urls::url_view& url, cookie c)
return;
}

// RFC 6265bis 5.3: replacing keeps the old cookie's position so creation
// RFC 6265bis 5.7 step 23: replacing keeps the old cookie's position so creation
// order (used for header ordering) is retained.
if(it != cookies_.end())
*it = std::move(c);
Expand Down Expand Up @@ -315,7 +315,7 @@ cookie_jar::cookie_header(const urls::url_view& url)
++it;
}

// RFC 6265 5.4: longer paths first; stable_sort keeps creation order as
// RFC 6265bis 5.8: longer paths first; stable_sort keeps creation order as
// the tiebreaker.
std::stable_sort(
matched.begin(),
Expand Down
2 changes: 1 addition & 1 deletion src/detail/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/beast2
// Official repository: https://github.com/cppalliance/burl
//

#include "util.hpp"
Expand Down
Loading
Loading