I'm trying to access the body of a response in some AfterMiddleware, response.body gets me a "ResponseBody".. I then tried using "write_all" to try to get access to the actual body.
For example this snippet:
impl AfterMiddleware for GzipAfterMiddleware {
fn after(&self, request: &mut Request, mut response: Response) -> IronResult {
//Check 'accept request' to see if the Request allows gzip, if so, gzip before sending.
let raw_accept_encoding = request.headers.get_raw("Accept-Encoding").unwrap();
for accept_encoding in raw_accept_encoding
{
println!("raw_accept_encoding: {}", str::from_utf8(accept_encoding).unwrap());
if str::from_utf8(accept_encoding).unwrap().to_lowercase().contains("gzip")
{
response.headers.set(ContentEncoding(vec![Encoding::Gzip]));
let mut encoder = GzEncoder::new(Vec::new(), Compression::Default);
match response.body {
Some(body) => //Who?
{
let mut respBody: ResponseBody;
let mut ActualContent: [u8];
body.write_body(&mut respBody);
respBody.write_all(&mut ActualContent);
//let ptr = (respBody as Box<Any + 'static>).downcast::<WriteBody>();
encoder.write_all(body);
let compressed_bytes = encoder.finish().unwrap();
Ok(compressed_bytes);
//compressed_bytes.modify(res);
},
None => Ok(response),
}
}
}
Ok(response)
}
The biggest issue I'm then getting is this error:
error[E0277]: the trait bound [u8]: std::marker::Sized
is not satisfied
--> src/main.rs:389:29
|
389 | let mut ActualContent: [u8];
| ^^^^^^^^^^^^^^^^^ the trait std::marker::Sized
is not implemented for [u8]
|
= note: [u8]
does not have a constant size known at compile-time
= note: all local variables must have a statically known size
Any thoughts? Thank you!!!