pub struct Compress { /* private fields */ }Expand description
Middleware for compressing response body.
Bodies with a known size below 1KiB are sent uncompressed.
Use BodyEncoding trait for overriding response compression.
To disable compression set encoding to ContentEncoding::Identity value.
use ntex::web::{self, middleware, App, HttpResponse};
fn main() {
let app = App::default()
.middleware(middleware::Compress::default())
.service(
web::resource("/test")
.route(web::get().to(async || { HttpResponse::Ok() }))
.route(web::head().to(async || { HttpResponse::MethodNotAllowed() }))
);
}Implementations§
Source§impl Compress
impl Compress
Sourcepub fn new(encoding: ContentEncoding) -> Self
pub fn new(encoding: ContentEncoding) -> Self
Create new Compress middleware with the specified encoding.
Use Compress::default() to select the encoding automatically
(ContentEncoding::Auto).
Trait Implementations§
Source§impl<S, St> Middleware<S, St> for Compress
impl<S, St> Middleware<S, St> for Compress
Source§fn create(&self, _: &St, service: S) -> Self::Service
fn create(&self, _: &St, service: S) -> Self::Service
Creates and returns a new middleware service.
Source§fn apply_to<Sf, Req>(
self,
factory: Sf,
) -> ServiceChainFactory<ApplyMiddleware<Self, Sf>, St, Req>
fn apply_to<Sf, Req>( self, factory: Sf, ) -> ServiceChainFactory<ApplyMiddleware<Self, Sf>, St, Req>
Creates a service factory that instantiates a service and applies
the current middleware to it. Read more
Auto Trait Implementations§
impl Freeze for Compress
impl RefUnwindSafe for Compress
impl Send for Compress
impl Sync for Compress
impl Unpin for Compress
impl UnsafeUnpin for Compress
impl UnwindSafe for Compress
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more