pub struct CustomizeResponder<R> { /* private fields */ }
Expand description
Implementations§
Source§impl<R> CustomizeResponder<R>where
R: Responder,
impl<R> CustomizeResponder<R>where
R: Responder,
Sourcepub fn with_status(self, status: StatusCode) -> CustomizeResponder<R>
pub fn with_status(self, status: StatusCode) -> CustomizeResponder<R>
Override a status code for the Responder’s response.
§Examples
use actix_web::{Responder, http::StatusCode, test::TestRequest};
let responder = "Welcome!".customize().with_status(StatusCode::ACCEPTED);
let request = TestRequest::default().to_http_request();
let response = responder.respond_to(&request);
assert_eq!(response.status(), StatusCode::ACCEPTED);
Sourcepub fn insert_header(
self,
header: impl TryIntoHeaderPair,
) -> CustomizeResponder<R>
pub fn insert_header( self, header: impl TryIntoHeaderPair, ) -> CustomizeResponder<R>
Insert (override) header in the final response.
Overrides other headers with the same name.
See HeaderMap::insert
.
Headers added with this method will be inserted before those added
with append_header
. As such, header(s) can be overridden with more
than one new header by first calling insert_header
followed by append_header
.
§Examples
use actix_web::{Responder, test::TestRequest};
let responder = "Hello world!"
.customize()
.insert_header(("x-version", "1.2.3"));
let request = TestRequest::default().to_http_request();
let response = responder.respond_to(&request);
assert_eq!(response.headers().get("x-version").unwrap(), "1.2.3");
Sourcepub fn append_header(
self,
header: impl TryIntoHeaderPair,
) -> CustomizeResponder<R>
pub fn append_header( self, header: impl TryIntoHeaderPair, ) -> CustomizeResponder<R>
Append header to the final response.
Unlike insert_header
, this will not override existing headers.
See HeaderMap::append
.
Headers added here are appended after additions/overrides from insert_header
.
§Examples
use actix_web::{Responder, test::TestRequest};
let responder = "Hello world!"
.customize()
.append_header(("x-version", "1.2.3"));
let request = TestRequest::default().to_http_request();
let response = responder.respond_to(&request);
assert_eq!(response.headers().get("x-version").unwrap(), "1.2.3");
Appends a cookie
to the final response.
§Errors
Final response will be an error if cookie
cannot be converted into a valid header value.
Trait Implementations§
Source§impl<T> Responder for CustomizeResponder<T>where
T: Responder,
impl<T> Responder for CustomizeResponder<T>where
T: Responder,
type Body = EitherBody<<T as Responder>::Body>
Source§fn respond_to(
self,
req: &HttpRequest,
) -> HttpResponse<<CustomizeResponder<T> as Responder>::Body>
fn respond_to( self, req: &HttpRequest, ) -> HttpResponse<<CustomizeResponder<T> as Responder>::Body>
Convert self to
HttpResponse
.Auto Trait Implementations§
impl<R> Freeze for CustomizeResponder<R>where
R: Freeze,
impl<R> RefUnwindSafe for CustomizeResponder<R>where
R: RefUnwindSafe,
impl<R> Send for CustomizeResponder<R>where
R: Send,
impl<R> Sync for CustomizeResponder<R>where
R: Sync,
impl<R> Unpin for CustomizeResponder<R>where
R: Unpin,
impl<R> UnwindSafe for CustomizeResponder<R>where
R: UnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more