Closed andrewtoth closed 11 months ago
Reading the old issue, it's been a while since I've thought about this. With some of the ecosystem recently worried about serde (not that I particularly agree with the worry itself), I find myself leaning back towards not including it directly in http
. 🙈
Other maintainers could disagree. But it seems sufficiently solvable with a separate crate.
A fair point. Thank you for sharing your thoughts on this. I've created a crate to solve this using the serde(with = "...")
attributes in case anyone else comes here looking for a solution.
https://crates.io/crates/http-serde-ext
This adds
serde::Serialize
andserde::Deserialize
trait implementations for all types re-exported at the root level, except forExtensions
,Result
, andError
.serde
is added as an optional dependency behind the feature flagserde1
.These are
HeaderMap, HeaderName, HeaderValue, Method, Request, Response, StatusCode, Uri, Version, request::Parts, response::Parts
. Note forRequest
andResponse
it will fail serialization ifextensions
is non-empty, and will deserialize to aExtensions::default()
.Current workarounds are to use the
http_serde
crate, but that requires annotating#[serde(with)]
and doesn't support usingOption
or other container types. Suggested alternatives are quite complex.There was a previous attempt just for
StatusCode
in https://github.com/hyperium/http/pull/274 which seems to have gone stale.Implements https://github.com/hyperium/http/issues/397, https://github.com/hyperium/http/issues/273, https://github.com/hyperium/http/issues/434