0.5: All the Async!
This is a huge release for cHTTP that delivers on first-class async
/.await
and big API ergonomic improvements! Read @sagebind's blog post if you want to learn even more about the release and the project's direction!
Breaking Changes
- Rename
Client
toHttpClient
andClientBuilder
toHttpClientBuilder
. For usability it helps to include the client type in our prelude, but the nameClient
is just a little too generic to do that. Using the nameHttpClient
is much less ambiguous as to what kind of client is in question. It's also a very common type name for HTTP clients and adds to familiarity. (#46) - The
Options
struct has been removed. Instead, request execution options can be set by using extension methods provided forhttp::request::Builder
, or by setting default configuration using methods available onHttpClientBuilder
. This greatly improves the ergonomics of setting various options, as well as allows you to override specific options piecemeal instead of overriding everything. (#35) Body
is now asynchronous internally. It still implementsRead
for ease of use, but you can no longer create a body from a synchronous reader. This fixes latency issues inside the agent thread, where previously sending and receiving bodies might block the entire event loop and prevent other parallel requests from making progress for a short time.
This also means that you can optionally read from a responseBody
within an asynchronous application without blocking. (#27)- The
json
feature no longer uses the json crate, and instead uses serde to automatically deserialize a JSON response to the target type. - Rename the
options
module toconfig
, and make several other redundant modules private. - Removed
Request
andResponse
Added
- Add a new
chttp::prelude
module that can be glob-imported to pull in the core types and traits you'll likely need to work with cHTTP. - In addition to the existing synchronous
send
,get
,post
(etc) methods, asynchronous versions of these methods are now available, suffixed with_async
. These methods do the exact same things as the synchronous versions, except entirely asynchronously and return aFuture
. (#27) - When creating a request body from a reader, you can now provide a length hint if you know the size of the body ahead of time. When providing a length hint, the hint will be used as the value of the
Content-Length
request header and be sent directly, instead of using a streaming encoding. - Add convenience methods
copy_to
andcopy_to_file
for downloading a response body to a file or an arbitrary writer.
Improvements
- The background agent thread that manages active requests has received many changes and improvements and is now fully asynchronous This offers less latency when multiple parallel requests are active and increased overall performance.
- Response buffers now use sluice which greatly increases the efficiency of reading from the HTTP response stream.
- Trim the dependency tree of crates that we don't really need, greatly improving both compile times and binary footprint. (#43) @sagebind
- Improve how we handle the Public Suffix List by bundling a copy via Git and refreshing it periodically during run time. This also removes the
psl
crate, which has been to compile very slowly. (#40)
Fixed
- Fix a bug where sending a HEAD request might hang waiting on the response until the server closes the connection.
- Fix various potential bugs in how certain HTTP verbs are handled by using explicit curl options for a verb if one exists.
- Fix some warning emitted by Clippy.
Changed
- Dropping a
Client
will now block until the associated agent thread shuts down. If the agent thread errors, it will propagate back to the main thread. - Replace usages of Rouille with Mockito in integration tests, as it has a lot of nice convenience methods and is a little lighter on the dependencies.