Skip to content

Commit 491a493

Browse files
committed
2.0.0-alpha.5
1 parent 5ce7996 commit 491a493

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

CHANGELOG.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,94 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview
77

88
## [Unreleased]
99

10+
## [2.0.0-alpha.5] - 2020-09-07
11+
12+
This is an alpha release in preparation of 2.0.0, so you can start using Surf with stable futures. There may be significant breaking changes before the final 2.0 release. Until thin, we recommend pinning to the particular alpha:
13+
14+
```toml
15+
[dependencies]
16+
surf = "= 2.0.0-alpha.5"
17+
```
18+
19+
This alpha release notably contains much more API parity with Tide, particularly for `surf::Request`, `surf::Response`, and `surf::middleware::Middleware`. Middleware also is now implemented using [async-trait](https://crates.io/crates/async-trait). Additionally, `surf::Client` is no longer generic and now instead holds the internal `HttpClient` as a dynamic trait object.
20+
21+
These changes mean that surf middleware must undergo the following changes:
22+
23+
**Old middleware:**
24+
```rust
25+
impl<C: HttpClient> Middleware<C> for Logger {
26+
fn handle<'a>(
27+
&'a self,
28+
req: Request,
29+
client: C,
30+
next: Next<'a, C>,
31+
) -> BoxFuture<'a, Result<Response, http_types::Error>> {
32+
Box::pin(async move {
33+
Ok(res)
34+
})
35+
}
36+
}
37+
```
38+
39+
**New middleware:**
40+
```rust
41+
#[surf::utils::async_trait]
42+
impl Middleware for Logger {
43+
async fn handle(
44+
&self,
45+
req: Request,
46+
client: Client,
47+
next: Next<'_>,
48+
) -> Result<Response> {
49+
Ok(res)
50+
}
51+
}
52+
```
53+
54+
This alpha release also contains large changes to how the `surf::Request` and `surf::Client` APIs are structured, adding a `surf::RequestBuilder` which is now returned from methods such as `surf::get(...)`. Overall usage structure was kept the same where possible and reasonable, however now a `surf::Client` must be used when using middleware.
55+
56+
```rust
57+
let client = surf::client()
58+
.with(some_middleware);
59+
60+
let req = surf::post(url) // Now returns a `surf::RequestBuilder`!
61+
.header(a_header, a_value)
62+
.body(a_body);
63+
let res = client.send(req).await?;
64+
```
65+
66+
# Additions
67+
- `surf::Request` added many methods that exist in `tide::Request`.
68+
- `surf::Response` added many methods that exist in `tide::Response`.
69+
- `surf::http`, an export of `http_types`, similar to `tide::http`.
70+
- `surf::middleware::Redirect`, a middleware to handle redirect status codes.
71+
- All conversions for `Request` and `Response` between `http_types` and `surf` now exist.
72+
73+
# Changes
74+
- `surf::Request` changed many methods to be like those in `tide::Request`.
75+
- `surf::Response` changed many methods to be like those in `tide::Response`.
76+
- Surf now uses `http-types::mime` instead of the `mime` crate.
77+
- `TryFrom<http_types::Request> for Request` is now `From<http_types::Request> for Request`.
78+
- `surf::Client` is no longer generic for `C: HttpClient`.
79+
- Middleware now receives `surf::Request` and returns `Result<surf::Response, E>`, and no longer requires a generic bound.
80+
- Middleware now uses [async-trait](https://crates.io/crates/async-trait), which is exported as `surf::utils::async_trait`.
81+
- The logger middleware is now exported as `surf::middleware::Logger`. (Note: this middleware is used by default.)
82+
- `surf::{method}()` e.g. `surf::get()` now returns a `surf::RequestBuilder` rather than a `surf::Request`.
83+
- Middleware can no longer be set for individual requests.
84+
- Instead, use a `surf::Client` and register middleware via `client.with(middleware)`.
85+
- Then, send the request from that client via `client.send()` e.g. `let res = client.send(request).await?;`.
86+
- `surf::Client` now can set a "base url" for that client via `client.set_base_url()`.
87+
88+
# Fixes
89+
- `From<http_types::Request> for Request` now properly propagates all properties.
90+
- A cloned `surf::Client` no longer adds middleware onto its ancestor's middleware stack.
91+
- Some feature flags are now correct.
92+
93+
# Internal
94+
- Use Clippy in CI.
95+
- Improved examples.
96+
- Now only depends on `futures_util` rather than all of `futures`.
97+
1098
## [2.0.0-alpha.2] - 2020-04-29
1199

12100
This is an alpha release in preparation of 2.0.0, so you can start using Surf with stable `futures`. There may be significant breaking changes before the final 2.0 release. Until then, we recommend pinning to the particular alpha:

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "surf"
3-
version = "2.0.0-alpha.4"
3+
version = "2.0.0-alpha.5"
44
license = "MIT OR Apache-2.0"
55
repository = "https://github.com/http-rs/surf"
66
documentation = "https://docs.rs/surf"

0 commit comments

Comments
 (0)