mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-01 16:55:08 +02:00
Move BodyEncoding to dev module #1220
This commit is contained in:
@ -9,34 +9,14 @@ use std::task::{Context, Poll};
|
||||
use actix_http::body::MessageBody;
|
||||
use actix_http::encoding::Encoder;
|
||||
use actix_http::http::header::{ContentEncoding, ACCEPT_ENCODING};
|
||||
use actix_http::{Error, Response, ResponseBuilder};
|
||||
use actix_http::Error;
|
||||
use actix_service::{Service, Transform};
|
||||
use futures::future::{ok, Ready};
|
||||
use pin_project::pin_project;
|
||||
|
||||
use crate::dev::BodyEncoding;
|
||||
use crate::service::{ServiceRequest, ServiceResponse};
|
||||
|
||||
struct Enc(ContentEncoding);
|
||||
|
||||
/// Helper trait that allows to set specific encoding for response.
|
||||
pub trait BodyEncoding {
|
||||
fn encoding(&mut self, encoding: ContentEncoding) -> &mut Self;
|
||||
}
|
||||
|
||||
impl BodyEncoding for ResponseBuilder {
|
||||
fn encoding(&mut self, encoding: ContentEncoding) -> &mut Self {
|
||||
self.extensions_mut().insert(Enc(encoding));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> BodyEncoding for Response<B> {
|
||||
fn encoding(&mut self, encoding: ContentEncoding) -> &mut Self {
|
||||
self.extensions_mut().insert(Enc(encoding));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
/// `Middleware` for compressing response body.
|
||||
///
|
||||
@ -155,8 +135,8 @@ where
|
||||
|
||||
match futures::ready!(this.fut.poll(cx)) {
|
||||
Ok(resp) => {
|
||||
let enc = if let Some(enc) = resp.response().extensions().get::<Enc>() {
|
||||
enc.0
|
||||
let enc = if let Some(enc) = resp.response().encoding() {
|
||||
enc
|
||||
} else {
|
||||
*this.encoding
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
#[cfg(feature = "compress")]
|
||||
mod compress;
|
||||
#[cfg(feature = "compress")]
|
||||
pub use self::compress::{BodyEncoding, Compress};
|
||||
pub use self::compress::Compress;
|
||||
|
||||
mod condition;
|
||||
mod defaultheaders;
|
||||
|
Reference in New Issue
Block a user