-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CookieStore trait and default Jar #1203
Conversation
I had just started commenting in #1105 in response to the various issues referencing it recently; so thank you @seanmonstar for picking this up. I think you've addressed the remaining questions I would have had there w.r.t. breaking change & Do you need any other feedback or changes from me? To me, this PR satisfies the use cases considered, and looks good to me. Once a release is published for |
9f174e3
to
26faada
Compare
No, not really. I was tagging you just in case you had thoughts, and so you knew the PR wasn't going to languish forever :) |
This adds a new trait, `CookieStore`, which allows for custom implementations of storage for a client's cookies. After implementing, you can call `ClientBuilder::cookie_provider` to use it over the default storage. The default store is exposed as `Jar`, to ease the most common use case which is to add a few cookies to the store when creating a client.
26faada
to
bd6c5c7
Compare
127: Bump tokio from 1.2.0 to 1.3.0 r=samueltardieu a=dependabot[bot] Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.2.0 to 1.3.0. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/tokio-rs/tokio/releases">tokio's releases</a>.</em></p> <blockquote> <h2>Tokio v1.3.0</h2> <h3>Added</h3> <ul> <li>coop: expose an <code>unconstrained()</code> opt-out (<a href="https://github.com/tokio-rs/tokio/issues/3547">#3547</a>)</li> <li>net: add <code>into_std</code> for net types without it (<a href="https://github.com/tokio-rs/tokio/issues/3509">#3509</a>)</li> <li>sync: add <code>same_channel</code> method to <code>mpsc::Sender</code> (<a href="https://github.com/tokio-rs/tokio/issues/3532">#3532</a>)</li> <li>sync: add <code>{try_,}acquire_many_owned</code> to <code>Semaphore</code> (<a href="https://github.com/tokio-rs/tokio/issues/3535">#3535</a>)</li> <li>sync: add back <code>RwLockWriteGuard::map</code> and <code>RwLockWriteGuard::try_map</code> (<a href="https://github.com/tokio-rs/tokio/issues/3348">#3348</a>)</li> </ul> <h3>Fixed</h3> <ul> <li>sync: allow <code>oneshot::Receiver::close</code> after successful <code>try_recv</code> (<a href="https://github.com/tokio-rs/tokio/issues/3552">#3552</a>)</li> <li>time: do not panic on <code>timeout(Duration::MAX)</code> (<a href="https://github.com/tokio-rs/tokio/issues/3551">#3551</a>)</li> </ul> <h3>Documented</h3> <ul> <li>doc: doc aliases for pre-1.0 function names (<a href="https://github.com/tokio-rs/tokio/issues/3523">#3523</a>)</li> <li>io: fix typos (<a href="https://github.com/tokio-rs/tokio/issues/3541">#3541</a>)</li> <li>io: note the EOF behaviour of <code>read_until</code> (<a href="https://github.com/tokio-rs/tokio/issues/3536">#3536</a>)</li> <li>io: update <code>AsyncRead::poll_read</code> doc (<a href="https://github.com/tokio-rs/tokio/issues/3557">#3557</a>)</li> <li>net: update <code>UdpSocket</code> splitting doc (<a href="https://github.com/tokio-rs/tokio/issues/3517">#3517</a>)</li> <li>runtime: add link to <code>LocalSet</code> on <code>new_current_thread</code> (<a href="https://github.com/tokio-rs/tokio/issues/3508">#3508</a>)</li> <li>runtime: update documentation of thread limits (<a href="https://github.com/tokio-rs/tokio/issues/3527">#3527</a>)</li> <li>sync: do not recommend <code>join_all</code> for <code>Barrier</code> (<a href="https://github.com/tokio-rs/tokio/issues/3514">#3514</a>)</li> <li>sync: documentation for <code>oneshot</code> (<a href="https://github.com/tokio-rs/tokio/issues/3592">#3592</a>)</li> <li>sync: rename <code>notify</code> to <code>notify_one</code> (<a href="https://github.com/tokio-rs/tokio/issues/3526">#3526</a>)</li> <li>time: fix typo in <code>Sleep</code> doc (<a href="https://github.com/tokio-rs/tokio/issues/3515">#3515</a>)</li> <li>time: sync <code>interval.rs</code> and <code>time/mod.rs</code> docs (<a href="https://github.com/tokio-rs/tokio/issues/3533">#3533</a>)</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/tokio-rs/tokio/commit/d0e4dd1d7ba8938cda3bf163b86d78ec16e2ee06"><code>d0e4dd1</code></a> chore: prepare Tokio v1.3.0 (<a href="https://github.com/tokio-rs/tokio/issues/3597">#3597</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/872bc09e837f63cfa1b0907fc16d3e21be6630ac"><code>872bc09</code></a> examples: update chat example (<a href="https://github.com/tokio-rs/tokio/issues/3587">#3587</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/db1d90453c04740176c354002b56da6f8cb30f2c"><code>db1d904</code></a> util: fuse PollSemaphore (<a href="https://github.com/tokio-rs/tokio/issues/3578">#3578</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/05eeea570e69f78b5937e807272551bc3075c073"><code>05eeea5</code></a> coop: expose an unconstrained() opt-out (<a href="https://github.com/tokio-rs/tokio/issues/3547">#3547</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/f70b9b84f7ac9c18b9b64ca52d3b4b594333b8e3"><code>f70b9b8</code></a> sync: documenation for oneshot (<a href="https://github.com/tokio-rs/tokio/issues/3592">#3592</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/704de8c01b331c2651c0cdb0d5ec6b0657e14344"><code>704de8c</code></a> stream: remove duplicate <code>doc(test(..))</code> & <code>cfg_attr</code> declarations (<a href="https://github.com/tokio-rs/tokio/issues/3571">#3571</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/47be928444babf84507a69ac42bb9c9447c78672"><code>47be928</code></a> sync: yield initial value in WatchStream (<a href="https://github.com/tokio-rs/tokio/issues/3576">#3576</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/e06b257e09b8ca1def4a3537a4448a31f2ede388"><code>e06b257</code></a> sync: add same_channel method to mpsc Senders (<a href="https://github.com/tokio-rs/tokio/issues/3532">#3532</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/0867a6fc0313b7ce0483e55956ebb0b2857a9a23"><code>0867a6f</code></a> util: add pollable mpsc::Sender (<a href="https://github.com/tokio-rs/tokio/issues/3490">#3490</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/0d838bf5ade7509e622559458a367cca65133f06"><code>0d838bf</code></a> io: fix link to std src in util (<a href="https://github.com/tokio-rs/tokio/issues/3568">#3568</a>)</li> <li>Additional commits viewable in <a href="https://github.com/tokio-rs/tokio/compare/tokio-1.2.0...tokio-1.3.0">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=tokio&package-manager=cargo&previous-version=1.2.0&new-version=1.3.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> 128: Bump reqwest from 0.11.0 to 0.11.2 r=samueltardieu a=dependabot[bot] Bumps [reqwest](https://github.com/seanmonstar/reqwest) from 0.11.0 to 0.11.2. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/seanmonstar/reqwest/releases">reqwest's releases</a>.</em></p> <blockquote> <h2>v0.11.2</h2> <ul> <li>Add <code>CookieStore</code> trait to customize the type that stores and retrieves cookies for a session.</li> <li>Add <code>cookie::Jar</code> as a default <code>CookieStore</code>, easing creating some session cookies before creating the <code>Client</code>.</li> <li>Add <code>ClientBuilder::http2_adaptive_window()</code> option to configure an adaptive HTTP2 flow control behavior.</li> <li>Add <code>ClientBuilder::http2_max_frame_size()</code> option to adjust the maximum HTTP2 frame size that can be received.</li> <li>Implement <code>IntoUrl</code> for <code>String</code>, making it more convenient to create requests with <code>format!</code>.</li> </ul> <h2>v0.11.1</h2> <ul> <li>Add <code>ClientBuilder::tls_built_in_root_certs()</code> option to disable built-in root certificates.</li> <li>Fix <code>rustls-tls</code> glue to more often support ALPN to upgrade to HTTP/2.</li> <li>Fix proxy parsing to assume <code>http://</code> if no scheme is found.</li> <li>Fix connection pool idle reaping by enabling hyper's <code>runtime</code> feature.</li> <li>(wasm) Add <code>Request::new()</code> constructor.</li> </ul> </blockquote> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md">reqwest's changelog</a>.</em></p> <blockquote> <h2>v0.11.2</h2> <ul> <li>Add <code>CookieStore</code> trait to customize the type that stores and retrieves cookies for a session.</li> <li>Add <code>cookie::Jar</code> as a default <code>CookieStore</code>, easing creating some session cookies before creating the <code>Client</code>.</li> <li>Add <code>ClientBuilder::http2_adaptive_window()</code> option to configure an adaptive HTTP2 flow control behavior.</li> <li>Add <code>ClientBuilder::http2_max_frame_size()</code> option to adjust the maximum HTTP2 frame size that can be received.</li> <li>Implement <code>IntoUrl</code> for <code>String</code>, making it more convenient to create requests with <code>format!</code>.</li> </ul> <h2>v0.11.1</h2> <ul> <li>Add <code>ClientBuilder::tls_built_in_root_certs()</code> option to disable built-in root certificates.</li> <li>Fix <code>rustls-tls</code> glue to more often support ALPN to upgrade to HTTP/2.</li> <li>Fix proxy parsing to assume <code>http://</code> if no scheme is found.</li> <li>Fix connection pool idle reaping by enabling hyper's <code>runtime</code> feature.</li> <li>(wasm) Add <code>Request::new()</code> constructor.</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/seanmonstar/reqwest/commit/80999a8963d2b579fb29a446e3ae238bbf55a7ad"><code>80999a8</code></a> v0.11.2</li> <li><a href="https://github.com/seanmonstar/reqwest/commit/12d7905520fee4cc96ca5e5a6d1fc523802cafc3"><code>12d7905</code></a> Add <code>CookieStore</code> trait and expose default <code>Jar</code> (<a href="https://github.com/seanmonstar/reqwest/issues/1203">#1203</a>)</li> <li><a href="https://github.com/seanmonstar/reqwest/commit/24140422690f9296fda2cd2007345ac2f942d12e"><code>2414042</code></a> replace match ... { } with matches! macro where possible (<a href="https://github.com/seanmonstar/reqwest/issues/1208">#1208</a>)</li> <li><a href="https://github.com/seanmonstar/reqwest/commit/a8566383168c0ef06c21f38cbc9213af6ff6db31"><code>a856638</code></a> Check format to all rs files under src (<a href="https://github.com/seanmonstar/reqwest/issues/1188">#1188</a>)</li> <li><a href="https://github.com/seanmonstar/reqwest/commit/9fa58e316d759ac00a14923ebbacde44ed2a5a22"><code>9fa58e3</code></a> Implement IntoUrl for String (<a href="https://github.com/seanmonstar/reqwest/issues/1201">#1201</a>)</li> <li><a href="https://github.com/seanmonstar/reqwest/commit/ff2381e61e0f814e63190546d23f553e9d77e61e"><code>ff2381e</code></a> Add http2_adaptive_window and htt2_max_frame_size from hyper (<a href="https://github.com/seanmonstar/reqwest/issues/1194">#1194</a>)</li> <li><a href="https://github.com/seanmonstar/reqwest/commit/6ac97dc3aaa6126ac6a6656efe47ad778c0892b5"><code>6ac97dc</code></a> Add minimal versions check for nightly CI job (<a href="https://github.com/seanmonstar/reqwest/issues/1197">#1197</a>)</li> <li><a href="https://github.com/seanmonstar/reqwest/commit/61a955c8218abdb09424469ce40eb37cbc0dea01"><code>61a955c</code></a> Bump mime to current version (<a href="https://github.com/seanmonstar/reqwest/issues/1196">#1196</a>)</li> <li><a href="https://github.com/seanmonstar/reqwest/commit/dabb878f32d1519467c7a8d98ae43d405345121d"><code>dabb878</code></a> update native-tls to v0.2.7 (<a href="https://github.com/seanmonstar/reqwest/issues/1183">#1183</a>)</li> <li><a href="https://github.com/seanmonstar/reqwest/commit/8689aa47e0750440849b39a2b94b19792c58ce62"><code>8689aa4</code></a> v0.11.1</li> <li>Additional commits viewable in <a href="https://github.com/seanmonstar/reqwest/compare/v0.11.0...v0.11.2">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=reqwest&package-manager=cargo&previous-version=0.11.0&new-version=0.11.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This adds a new trait, `CookieStore`, which allows for custom implementations of storage for a client's cookies. After implementing, you can call `ClientBuilder::cookie_provider` to use it over the default storage. The default store is exposed as `Jar`, to ease the most common use case which is to add a few cookies to the store when creating a client. Co-authored-by: Patrick Fernie <patrick.fernie@gmail.com>
This adapts #1105, with a few adjustments. Firstly, as in #1105, this adds a
CookieStore
trait so that users can customize where cookies are stored and retrieved on the Client. The adjustments include:CookieStore
so as to need less allocations. It does make implementing them a little more annoying.ClientBuilder::cookie_store
still take a boolean usingcookie_store
crate as the implementation, and addsClientBuilder::cookie_provider
which takes a genericArc<impl CookieStore>
.reqwest::cookie::Jar
, and it has a simpleadd_cookie_str
method.cc @pfernie