Releases: http-rs/http-types
v2.3.0
This release one bug and adds several non-breaking enhancements.
Bugfix:
- #189 adds std::marker::Sync to the return type of Body::into_reader
Enhancements:
- #188 Adds
as_str
to http_types::mime::ParamName and http_types::mime::ParamValue - #194 Adds http dav extension status code 207
- #196 Adds an XML mime constant and matches the .xml file extension to it
- #197 Adds a public Mime::from_extension, exposing file extension matching outside of the http-types
- #199 Adds Body::mime() and Body::set_mime(), allowing external crates to set a custom mime type on a body
Internal:
- #178 http-types now conforms to clippy lints and CI runs clippy by default
v2.2.1
v2.2.0
This patch introduces a new experimental trace
submodule and improves the Debug
output for headers.
Trace submodule
Tracking requests as they flow through services is a useful capability. To that extent the W3C has drafted a specification for standardized headers to "trace" requests through layers of servers. The trace
submodule now contains a TraceContext
object that has the logic required to parse, encode, and correlate requests with each other.
In the future we hope to be able to provide integrations in tide
and turf
so that when you create a request from a tide
endpoint using surf
, the two can automatically be correlated.
Better Debug output for Headers
Printing Headers
used to show various internal structures and hierarchies. Thanks to @jreyes33 the debug output of headers has become much easier to parse:
[src/request.rs:992] &request = Request {
method: Get,
url: "http://async.rs/",
headers: {
"single": "foo0",
"multi": [
"foo1",
"foo2",
],
},
version: None,
}
Added
- Add
trace
submodule as "unstable" #172
Changed
Internal
- Add CI job for wasm32-unknown-unknown #166
v2.1.0
This patch makes it easier to construct new requests, added more flexible bounds for the Status
trait, and enabled secure cookies support out of the box. Additionally we're now experimenting with a new upgrade
submodule that will enable us to upgrade connections to e.g. websockets in a generic fashion.
Example
Creating new requests is now easier:
let req = Request::get(Url::parse("https://soup.onion").unwrap());
In the future this will become even easier once the patch introducing TryFrom<&str>
bounds for Url
are released. This will remove the need to call Url::parse(...).unwrap()
and will allow passing string literals to Request
.
The Status
trait is now more flexible as well:
let buf = fs::read("./my-file").await.status(StatusCode::NotFound)?;
// This patch now allows doing this as well.
let buf = fs::read("./my-file").await.status(404)?;
Added
- Added method shorthands for Request constructor #159
- Status takes
TryInto<StatusCode>
#157 - Added feature for enabling signed and encrypted cookie support #152 #165
- Added the
upgrade
submodule as "unstable" #115
Fixes
- Made
Request::query
behavior consistent with Tide #162 - Fixed links to the CONTRIBUTING page from the README #158
- Body parse errors return status 422 #163
- Fixed compilation on wasm32-unknown-unknown #153
Internal
- Define
Mime
constants using macros #160
v2.0.1
This patch updates an outdated dependency and fixes a bug that we found after releasing 2.0.0. Neither patch has required any changes in http-types
' test suite or documentation, and we feel fairly confident most people won't need to change their code because of this patch.
Changed
- Update dependencies #150
Fixed
Request
andResponse
body_*
methods now take&mut self
rather thanself
#151
v2.0.0
This patch makes it significantly easier to work with headers in http-types
, introduces new status code constants, header constants, tweaks some APIs we didn't get around the first time around.
Header types now include various PartialEq
comparisons that weren't possible before. This makes it significantly easier to construct new headers, but also assert headers in tests:
// http-types 1.x
assert_eq!(req.header(&"X-Forwarded-For".parse().unwrap()), Some(&vec!["127.0.0.1".parse().unwrap()]));
// http-types 2.x
assert_eq!(req.header["X-Forwarded-For"], "127.0.0.1");
In addition many of our constructors now take TryInto
values, which provides useful shorthands in places where unwrap
was common. This should make it easier to construct both new Request
and Response
types.
Upgrade notes
This patch removes the Result
type from the header*
family of methods and the request/response constructors. In the past Result<Option<Value>>
was returned to among other things catch ASCII conversion errors. This was usually handled simply by calling unwrap
. However since APIs here now return Option
instead of Result<Option>
, unwrap
will still be valid in code, but may unexpectedly panic. We recommend validating that header*
methods are no longer being unwrapped.
let mut req = ...;
// The signature used to be `Result<Option<HeaderValue>>`
// and `unwrap` would cause a panic if `Err` was returned.
let val = req.header("my-header").unwrap();
// But now the signature is `Option<HeaderValue>` and
// `unwrap` will cause a panic if `None` is returned.
let val = req.header("my-header").unwrap();
// The solution is to remove additional `unwrap`s.
let val = req.header("my-header");
// However if you need to construct a header from user input,
// errors can be caught by constructing the header separately.
let name: HeaderName = "my-header".try_into().expect("invalid ascii");
let val = req.header(name);
Added
- Implement
Clone
forRequest
andResponse
#91 - Added various
From
conversions forBody
,Request
, andResponse
#101 #100 - Added logos to docs.rs #111
- Added status codes 422, 423, 424, 507, 508 #112 #114
- Added all header constants from RFC2616 #107
- Added
Request::{peer_addr, local_addr}
andRequest::{set_peer_addr, set_local_addr}
#119 - Implemented
Index
forHeaders
, enablingreq["name"]
-style lookup #110 - Added
Request::host
andRequest::remote
#131 #119 - Added mime sniffing to
Body::from_file
#132 - Added
Request::{set_query, query}
#143
Changed
- Reworked
trailers
to no longer return aResult
and renamed the types in the submodule #103 - We're now able to initialize mime constants with parameters, which means some constants now include utf-8 encoding #105
- Replaced
Vec<HeaderValue>
withHeaderValues
. This enabled more conversions and easier comparisons #109 - Modified the MIME parser to 1:1 follow the WHATWG algorithm #122
- Renamed
TypeMap
toExtensions
#118 - Header operations no longer return
Result
and consistently takeTryFrom
#127 - Request and Response constructors now take arguments using
TryFrom
#127 - The
percent-encoding
feature on thecookies
dependency is now always enabled #134
Removed
- Removed the cookie APIs from Request and Response #111