You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This major release of Surf contains substantial improvements through a variety of changes and additions.
(Note: this is a cumulative list of changes since Surf 1.0.3)
Notable mentions include:
- Uses stable standard library `futures`!
- Much more type compatibility with Tide via http-types!
- Re-usable `Client` which is able to make use of connection pooling under the hood.
- Reduced generics for `Client` and `Middleware`.
- Re-worked `Middleware` to use `async_trait`.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+169Lines changed: 169 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,175 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview
7
7
8
8
## [Unreleased]
9
9
10
+
## [2.0.0] - 2020-10-05
11
+
12
+
[Docs](https://docs.rs/surf/2.0.0)
13
+
14
+
This major release of Surf contains substantial improvements through a variety of changes and additions.
15
+
16
+
_(Note: this is a cumulative list of changes since Surf 1.0.3)_
17
+
18
+
Notable mentions include:
19
+
- Uses stable standard library [`futures`][]!
20
+
- Much more type compatibility with [Tide][] via [http-types][]!
21
+
- Re-usable `Client` which is able to make use of connection pooling [under the hood](https://github.com/http-rs/http-client).
22
+
- Reduced generics for `Client` and `Middleware`.
23
+
- Re-worked `Middleware` to use [`async_trait`][].
24
+
25
+
### Major Changes
26
+
Surf 2 contains some large API changes, as noted here:
27
+
28
+
#### http-types
29
+
30
+
Surf has switched the common backing type interface (`surf::http`) from the [http][] (`hyperium/http`) crate to [http-types][], which covers a larger set of HTTP-related functionality than `hyperium/http` does, and allows Surf to use the [url standard][].
31
+
32
+
This affects any type that came from `surf::http`, such as `StatusCode` ([old][StatusCode http]|[new][StatusCode http-types]), and includes some new patterns, such as [`Body`][].
33
+
34
+
For more information, see [this blog post](https://blog.yoshuawuyts.com/async-http/#shared-abstractions).
35
+
36
+
#### Errors
37
+
38
+
`surf::Exception`, which was a plain `Box<dyn Error + Send + Sync + 'static>`, is no more.
39
+
40
+
Surf now exports a structured [`surf::Error`][] type, which holds a `StatusCode` alongside a dynamic error object.
41
+
Just like [`anyhow`][], any error can be cast to this type using the `?` operator.
42
+
43
+
For more information, see [this blog post](https://blog.yoshuawuyts.com/async-http/#error-handling).
44
+
45
+
#### Middleware
46
+
47
+
**New middleware:**
48
+
```rust
49
+
usesurf::middleware::{Middleware, Next};
50
+
usesurf::{Client, Request, Response, Result};
51
+
52
+
#[surf::utils::async_trait]
53
+
implMiddlewareforLogger {
54
+
asyncfnhandle(
55
+
&self,
56
+
req:Request,
57
+
client:Client,
58
+
next:Next<'_>,
59
+
) ->Result<Response> {
60
+
Ok(res)
61
+
}
62
+
}
63
+
```
64
+
65
+
#### RequestBuilder
66
+
67
+
The top-level convenience request methods, `surf::get()`, `surf::post()`, etc, now return a [`RequestBuilder`][] rather than a [`Request`][] directly.
68
+
Most `RequestBuilder` functions have shorthand names: `RequestBuilder::body()` compared to `Request::set_body()`.
69
+
70
+
```rust
71
+
letres=surf::get("http://example.org") // Now returns a `surf::RequestBuilder`!
72
+
.header(a_header, a_value)
73
+
.body(a_body)
74
+
.await?;
75
+
```
76
+
77
+
Overall usage was kept the same where possible and reasonable, however now a `surf::Client` must be used when using middleware.
78
+
79
+
```rust
80
+
letclient=surf::client()
81
+
.with(some_middleware);
82
+
83
+
letres=client::post(url)
84
+
.header(a_header, a_value)
85
+
.body(a_body)
86
+
.await?;
87
+
```
88
+
89
+
Alternately:
90
+
```rust
91
+
letclient=surf::client()
92
+
.with(some_middleware);
93
+
94
+
letreq=surf::post(url)
95
+
.header(a_header, a_value)
96
+
.body(a_body);
97
+
letres=client.send(req).await?;
98
+
```
99
+
100
+
#### Mime
101
+
102
+
Surf has switched from the [`mime`][] crate to [`surf::http::Mime`][] from [http-types][].
103
+
104
+
For more information, see [this blog post](https://blog.yoshuawuyts.com/async-http/#shared-abstractions).
105
+
106
+
### Additions
107
+
- Switched from [`hyperium/http`][http] to [http-types][].
108
+
-`surf::Request` added many methods that exist in `tide::Request`.
109
+
-`surf::Response` added many methods that exist in `tide::Response`.
110
+
-`surf::http`, an export of `http_types`, similar to `tide::http`.
111
+
-`surf::middleware::Redirect`, a middleware to handle redirect status codes.
112
+
- All conversions for `Request` and `Response` between `http_types` and `surf` now exist.
113
+
-`http_types::{Error, Result}` are re-exported as `surf::{Error, Result}`.
114
+
- A new `h1-client` feature enables the new [async-h1] backend.
115
+
- Transcode responses from non-UTF8 charsets using the on-by-default `encoding` feature.
116
+
117
+
### Removals
118
+
- Removed `native-client` feature flag in favor of direct `curl-client` default.
0 commit comments