I'm trying to write a reverse proxy that caches Hyper responses in memory. The proxy receives a request, forwards it to an upstream server, returns the response. Current code is at https://github.com/klausi/rustnish/blob/goal-10/src/lib.rs
Attempt 1: use LruCache::<String, Response<Body>>
as in the code above. Compile error:
error[E0277]: `(dyn futures::Stream<Item=hyper::Chunk, Error=std::boxed::Box<(dyn std::error::Error + std::marker::Send + std::marker::Sync + 'static)>> + std::marker::Send + 'static)` cannot be shared between threads safely
--> src/lib.rs:169:13
|
169 | tokio::spawn(
| ^^^^^^^^^^^^ `(dyn futures::Stream<Item=hyper::Chunk, Error=std::boxed::Box<(dyn std::error::Error + std::marker::Send + std::marker::Sync + 'static)>> + std::marker::Send + 'static)` cannot be shared between threads safely
|
= help: the trait `std::marker::Sync` is not implemented for `(dyn futures::Stream<Item=hyper::Chunk, Error=std::boxed::Box<(dyn std::error::Error + std::marker::Send + std::marker::Sync + 'static)>> + std::marker::Send + 'static)`
= note: required because of the requirements on the impl of `std::marker::Sync` for `std::ptr::Unique<(dyn futures::Stream<Item=hyper::Chunk, Error=std::boxed::Box<(dyn std::error::Error + std::marker::Send + std::marker::Sync + 'static)>> + std::marker::Send + 'static)>`
= note: required because it appears within the type `std::boxed::Box<(dyn futures::Stream<Item=hyper::Chunk, Error=std::boxed::Box<(dyn std::error::Error + std::marker::Send + std::marker::Sync + 'static)>> + std::marker::Send + 'static)>`
= note: required because it appears within the type `hyper::body::body::Kind`
= note: required because it appears within the type `hyper::Body`
= note: required because it appears within the type `hyper::Response<hyper::Body>`
...
Hm, seems like Response<Body>
cannot be used directly in the cache. What data structure do I need to convert Response
into so that it can be put into a cache?