New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update bytes dep to 0.6 + update lock file #107
Conversation
Unfortunately this is a breaking change because it's publicly visible that I'm hoping not to publish any breaking changes until |
@blacktemplar do you have some usecase where you need this? I don't really like the current stream API and it would be interesting to look at all users of it and see if there's a better API that could be used (e.g. just using the cc @seanmonstar as reqwest and warp are the biggest users of it, and I assume this will impact the tokio0.3/bytes0.6 transition for them. |
Hm, I will need this, but I understand not wanting to make breaking changes to this library. Perhaps integrating with Or another option is to add |
The need occurred when we tried to update our application (https://github.com/sigp/lighthouse) and a lot of its dependencies to Tokio 0.3. Specifically we needed it for updating the warp dependency (sigp/warp@22ab423). |
Ok, so it's the same hyper related usecase as all the other usage of the @seanmonstar are there any planned changes to |
There are a few changes coming in hyper v0.14. |
But fundamentally |
That sounds right. I'm not sure what you have in mind, but I'd personally keep the |
As an alternative, |
@Nemo157 I've applied your patch in seanmonstar/reqwest#1076, thanks! |
So I have code roughly like this: let orig = mem::replace(rsp.body_mut(), Body::empty());
rsp.headers_mut()
.insert(CONTENT_ENCODING, HeaderValue::from_static("br"));
*rsp.body_mut() = Body::wrap_stream(BrotliEncoder::new(
orig.map_err(|e| io::Error::new(io::ErrorKind::Other, e)),
));
rsp How would I rewrite this while using hyper 0.14 and its error[E0271]: type mismatch resolving `<hyper::Body as Stream>::Item == std::result::Result<bytes::bytes::Bytes, _>`
--> mendes/src/hyper.rs:113:53
|
113 | *rsp.body_mut() = Body::wrap_stream(BrotliEncoder::new(
| ^^^^^^^^^^^^^^^^^^ expected struct `bytes::Bytes`, found struct `bytes::bytes::Bytes`
|
= note: expected enum `std::result::Result<bytes::Bytes, hyper::Error>`
found enum `std::result::Result<bytes::bytes::Bytes, _>`
= note: perhaps two different versions of crate `bytes` are being used?
= note: required because of the requirements on the impl of `TryStream` for `hyper::Body`
= note: required because of the requirements on the impl of `Stream` for `futures_util::stream::Map<futures_util::stream::IntoStream<hyper::Body>, futures_util::fns::MapErrFn<[closure@mendes/src/hyper.rs:114:34: 114:77]>>`
= note: required by `BrotliEncoder::<S>::new` |
Something similar to: Body::wrap_stream(tokio_util::codec::FramedRead::new(
BrotliEncoder::new(tokio_util::io::StreamReader::new(orig)),
tokio_util::codec::BytesCodec::new(),
)); Maybe with mapping the error, I don't recall what My plan is probably to add docs on how to migrate to the |
You mean, migrate to the I tried to implement your suggestion but can't figure it out so far. I can create a I'd suggest that life for server-side hyper users of your crate would be a whole lot easier if you just make the bump to 0.4 with bytes 1.0 for now, jumping to 1.0 once |
Oh, use
I meant "add docs within |
I've opened #115 to deprecate, with a link to the rendered migration docs. If anyone has any feedback on the deprecation or docs I'd appreciate it in there. |
@Nemo157 thanks for the docs! The docs seem to only cover encoding. I originally got the same error as @djc (with a I'm trying to decode the I've included a minimal sample below of the sort of thing I'm trying to do. let body = tokio_util::io::StreamReader::new(body.map_err(|e| IOError::new(ErrorKind::Other, e)));
let identity = BrotliDecoder::new(body);
let encoded = GzipEncoder::new(identity); I end up with an error like this:
|
The let body = tokio_util::io::StreamReader::new(body.map_err(|e| IOError::new(ErrorKind::Other, e)));
let identity = BrotliDecoder::new(body);
let encoded = GzipEncoder::new(tokio::io::BufReader::new(identity)); |
Here's my change: @@ -63,14 +63,15 @@ mod encoding {
use std::{io, mem};
#[cfg(feature = "brotli")]
- use async_compression::stream::BrotliEncoder;
+ use async_compression::tokio::bufread::BrotliEncoder;
@@ -113,9 +114,9 @@ mod encoding {
let orig = mem::replace(rsp.body_mut(), Body::empty());
rsp.headers_mut()
.insert(CONTENT_ENCODING, HeaderValue::from_static("br"));
- *rsp.body_mut() = Body::wrap_stream(BrotliEncoder::new(
- orig.map_err(|e| io::Error::new(io::ErrorKind::Other, e)),
- ));
+ *rsp.body_mut() = Body::wrap_stream(ReaderStream::new(BrotliEncoder::new(
+ StreamReader::new(orig.map_err(|e| io::Error::new(io::ErrorKind::Other, e))),
+ )));
rsp
}
#[cfg(feature = "gzip")] @Nemo157 are there any advantages to the |
I didn't realise |
Now that #115 is merged and released in 0.3.8 I'm closing this, migration docs can be seen at https://docs.rs/async-compression/0.3.8/async_compression/stream/index.html |
No description provided.