All notable changes to surf will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
If you use the h1-client
, upgrading to this release is reccomended.
h1-client-rustls
feature flag, for using theasync-h1
client withrustls
as the TLS backend.- The TLS backend for
h1-client
is stillasync-native-tls
.
- The TLS backend for
- Per-request middleware, provided by
RequestBuilder::middleware(&mut self, impl Middleware)
. AsRef<Headers>
andAsMut<Headers>
forsurf::Request
andsurf::Response
.
- Relative redirects should now be handled by the
RedirectMiddleware
. - The
h1-client
feature should now properly work withhttp-client
6.3.0+ without additional feature specification.
- The
http
docs now link to the live, up-to-datehttp_types
docs.
- Various CI improvements.
This minor release contains follow-up fixes and improvements to Surf 2.0.
- Added a
hyper-client
cargo feature for enabeling a hyper client backend via http-client.
- Fixed
base_url
not being propagated to theClient
instance in middleware.
- Updated documentation for
set_base_url()
.
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
andMiddleware
. - Re-worked
Middleware
to useasync_trait
.
Surf 2 contains some large API changes, as noted here:
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.
This affects any type that came from surf::http
, such as StatusCode
(old|new), and includes some new patterns, such as Body
.
For more information, see this blog post.
surf::Exception
, which was a plain Box<dyn Error + Send + Sync + 'static>
, is no more.
Surf now exports a structured surf::Error
type, which holds a StatusCode
alongside a dynamic error object.
Just like anyhow
, any error can be cast to this type using the ?
operator.
For more information, see this blog post.
New middleware:
use surf::middleware::{Middleware, Next};
use surf::{Client, Request, Response, Result};
#[surf::utils::async_trait]
impl Middleware for Logger {
async fn handle(
&self,
req: Request,
client: Client,
next: Next<'_>,
) -> Result<Response> {
Ok(res)
}
}
The top-level convenience request methods, surf::get()
, surf::post()
, etc, now return a RequestBuilder
rather than a Request
directly.
Most RequestBuilder
functions have shorthand names: RequestBuilder::body()
compared to Request::set_body()
.
let res = surf::get("http://example.org") // Now returns a `surf::RequestBuilder`!
.header(a_header, a_value)
.body(a_body)
.await?;
Overall usage was kept the same where possible and reasonable, however now a surf::Client
must be used when using middleware.
let client = surf::client()
.with(some_middleware);
let res = client::post(url)
.header(a_header, a_value)
.body(a_body)
.await?;
Alternately:
let client = surf::client()
.with(some_middleware);
let req = surf::post(url)
.header(a_header, a_value)
.body(a_body);
let res = client.send(req).await?;
Surf has switched from the mime
crate to surf::http::Mime
from http-types.
For more information, see this blog post.
- Switched from
hyperium/http
to http-types. surf::Request
added many methods that exist intide::Request
.surf::Response
added many methods that exist intide::Response
.surf::http
, an export ofhttp_types
, similar totide::http
.surf::middleware::Redirect
, a middleware to handle redirect status codes.- All conversions for
Request
andResponse
betweenhttp_types
andsurf
now exist. http_types::{Error, Result}
are re-exported assurf::{Error, Result}
.- A new
h1-client
feature enables the new async-h1 backend. - Transcode responses from non-UTF8 charsets using the on-by-default
encoding
feature.
- Removed
native-client
feature flag in favor of directcurl-client
default. - Removed
hyper-client
feature flag. (Pending re-addition, see: #234) - Removed
Request::body_string()
,Request::body_json()
, etc.- This functionality is now done via
Body
, orClient::recv_json()
,RequestBuilder::recv_json()
, etc.
- This functionality is now done via
- Updated to use stable
futures
. wasm-client
feature is no longer automatic and must be set via cargo features.- All client feature flags are now mutually exclusive.
curl-client
is the default. surf::method_name
"one-off" methods now use a shared client internally if the client iscurl-client
. (Default)Client::with_http_client()
is now generic for anyHttpClient
rather than taking anArc<dyn HttpClient>
.- (The http client is still stored internally as a dynamic pointer.)
HttpClient
has been upgraded to 6.0, removingClone
from the built in client backends.surf::Request
changed many methods to be like those intide::Request
.surf::Response
changed many methods to be like those intide::Response
.- Surf now uses
http-types::mime
instead of themime
crate. TryFrom<http_types::Request> for Request
is nowFrom<http_types::Request> for Request
.surf::Client
is no longer generic forC: HttpClient
.- Middleware now receives
surf::Request
and returnsResult<surf::Response, E>
, and no longer requires a generic bound. - Middleware now uses async-trait, which is exported as
surf::utils::async_trait
. - The logger middleware is now exported as
surf::middleware::Logger
. (Note: this middleware is used by default.) surf::{method}()
e.g.surf::get()
now returns asurf::RequestBuilder
rather than asurf::Request
.- Middleware can no longer be set for individual requests.
- Instead, use a
surf::Client
and register middleware viaclient.with(middleware)
. - Then, send the request from that client via
client.send()
e.g.let res = client.send(request).await?;
.
surf::Client
now can set a "base url" for that client viaclient.set_base_url()
.Client
is now built on top ofhttp-client
.surf::url
has been moved tosurf::http::url
, with asurf::Url
shortcut.
- Reduce copies when parsing URLs.
- Now only depends on
futures_util
rather than all offutures
. wasm-client
now has proper headless browser CI testing.- Use Clippy in CI.
- Set up an MSRV in CI.
- Stop hitting the network when running tests.
- Added:
RequestBuilder
now has a.query()
function for setting structured querystrings. - Changed:
Client::send()
andRequestBuilder::send()
are now plain async functions and no longer returnBoxFuture
s. - Changed:
surf::url
has been moved tosurf::http::url
, with asurf::Url
shortcut.
- Downgrade rust_2018_idioms from forbid to warn for compilation with newer deps.
This is an alpha release in preparation of 2.0.0, so you can start using Surf with stable futures. The aim is for this to be the last 2.0 alpha release.
As of this release, surf::get()
, surf::post()
, etc, now use a globally shared client internally, allowing for easier access to optimizations such as connection pooling.
- Removed
native-client
feature flag in favor of directcurl-client
default.
wasm-client
feature is no longer automatic and must be set via cargo features.- All client feature flags are now mutually exclusive.
curl-client
is the default. surf::method_name
"one-off" methods now use a shared client internally if the client iscurl-client
. (Default)Client::with_http_client()
is now generic for anyHttpClient
rather than taking anArc<dyn HttpClient>
.- (The http client is still stored internally as a dynamic pointer.)
HttpClient
has been upgraded to 6.0, removingClone
from the built in client backends.
- Surf can once again build with
--no-default-features
(and no client). - Doc updates
wasm-client
now has proper headless browser CI testing.
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:
[dependencies]
surf = "= 2.0.0-alpha.5"
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. Additionally, surf::Client
is no longer generic and now instead holds the internal HttpClient
as a dynamic trait object.
These changes mean that surf middleware must undergo the following changes:
Old middleware:
impl<C: HttpClient> Middleware<C> for Logger {
fn handle<'a>(
&'a self,
req: Request,
client: C,
next: Next<'a, C>,
) -> BoxFuture<'a, Result<Response, http_types::Error>> {
Box::pin(async move {
Ok(res)
})
}
}
New middleware:
#[surf::utils::async_trait]
impl Middleware for Logger {
async fn handle(
&self,
req: Request,
client: Client,
next: Next<'_>,
) -> Result<Response> {
Ok(res)
}
}
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.
let client = surf::client()
.with(some_middleware);
let req = surf::post(url) // Now returns a `surf::RequestBuilder`!
.header(a_header, a_value)
.body(a_body);
let res = client.send(req).await?;
surf::Request
added many methods that exist intide::Request
.surf::Response
added many methods that exist intide::Response
.surf::http
, an export ofhttp_types
, similar totide::http
.surf::middleware::Redirect
, a middleware to handle redirect status codes.- All conversions for
Request
andResponse
betweenhttp_types
andsurf
now exist.
surf::Request
changed many methods to be like those intide::Request
.surf::Response
changed many methods to be like those intide::Response
.- Surf now uses
http-types::mime
instead of themime
crate. TryFrom<http_types::Request> for Request
is nowFrom<http_types::Request> for Request
.surf::Client
is no longer generic forC: HttpClient
.- Middleware now receives
surf::Request
and returnsResult<surf::Response, E>
, and no longer requires a generic bound. - Middleware now uses async-trait, which is exported as
surf::utils::async_trait
. - The logger middleware is now exported as
surf::middleware::Logger
. (Note: this middleware is used by default.) surf::{method}()
e.g.surf::get()
now returns asurf::RequestBuilder
rather than asurf::Request
.- Middleware can no longer be set for individual requests.
- Instead, use a
surf::Client
and register middleware viaclient.with(middleware)
. - Then, send the request from that client via
client.send()
e.g.let res = client.send(request).await?;
.
surf::Client
now can set a "base url" for that client viaclient.set_base_url()
.
From<http_types::Request> for Request
now properly propagates all properties.- A cloned
surf::Client
no longer adds middleware onto its ancestor's middleware stack. - Some feature flags are now correct.
- Use Clippy in CI.
- Improved examples.
- Now only depends on
futures_util
rather than all offutures
.
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:
[dependencies]
surf = "= 2.0.0-alpha.2"
http_types::{Error, Result}
are re-exported assurf::{Error, Result}
http-rs#163
- Add http-rs logo for docs.rs. http-rs#165
- Removed dependencies that are no longer necessary since the switch to
http-client
in 2.0.0-alpha.0 http-rs#164
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:
[dependencies]
surf = "= 2.0.0-alpha.1"
h1-client
backend is now available http-rs#146
- Updated
http-client
to v2.0.0 - Switched from
hyperium/http
tohttp-types
http-rs#146
- Updated
mime-guess
requirement http-rs#148
2.0.0-alpha.0 - 2020-03-02
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:
[dependencies]
surf = "= 2.0.0-alpha.0"
- Transcode responses from non-UTF8 charsets.
- Updated to use stable
futures
. - Build on top of
http-client
. - Set up an MSRV in CI.
- Stop hitting the network when running tests.
- Reduce copies when parsing URLs.
- Fix syntax errors in the README.md example.
- Fix links in CHANGELOG.md after the org move in 1.0.3.
1.0.3 - 2019-11-07
- Migrated the project from the
rustasync
organization tohttp-rs
. - Migrated CI providers from Travis CI to GitHub Actions.
- Replaced
runtime
withasync-std
in examples. - Error context no longer discards the inner error body.
- Updated the README.md formatting.
- Updated
futures-preview
to0.3.0-alpha.19
1.0.2 - 2019-08-26
Log not kept.
1.0.1 - 2019-08-15
Log not kept.
1.0.0 - 2019-08-15
Log not kept.