pub struct Response<S: ResponseCode = StatusCode> { /* private fields */ }Expand description
An HTTP response.
Implementations§
source§impl<S: ResponseCode> Response<S>
impl<S: ResponseCode> Response<S>
sourcepub fn with_context<Ctx: RequestContext>(code: S, ctx: &Ctx) -> Self
pub fn with_context<Ctx: RequestContext>(code: S, ctx: &Ctx) -> Self
Creates a new instance with the request context.
sourcepub fn context<Ctx: RequestContext>(self, ctx: &Ctx) -> Self
pub fn context<Ctx: RequestContext>(self, ctx: &Ctx) -> Self
Provides the request context for the response.
sourcepub fn render<T: Serialize>(self, template_name: &str, data: T) -> Self
Available on crate feature view only.
pub fn render<T: Serialize>(self, template_name: &str, data: T) -> Self
view only.Renders a template and sets it as the reponse data.
sourcepub fn set_status_code(&mut self, status_code: impl Into<u16>)
pub fn set_status_code(&mut self, status_code: impl Into<u16>)
Sets the status code.
sourcepub fn set_error_code(&mut self, error_code: impl Into<S::ErrorCode>)
pub fn set_error_code(&mut self, error_code: impl Into<S::ErrorCode>)
Sets the error code.
sourcepub fn set_business_code(&mut self, business_code: impl Into<S::BusinessCode>)
pub fn set_business_code(&mut self, business_code: impl Into<S::BusinessCode>)
Sets the bussiness code.
sourcepub fn set_instance(&mut self, instance: impl Into<SharedString>)
pub fn set_instance(&mut self, instance: impl Into<SharedString>)
Sets a URI reference that identifies the specific occurrence of the problem.
sourcepub fn set_message(&mut self, message: impl Into<SharedString>)
pub fn set_message(&mut self, message: impl Into<SharedString>)
Sets the message. If the response is not successful, it should be a human-readable explanation specific to this occurrence of the problem.
sourcepub fn set_error_message(&mut self, error: impl Into<Error>)
pub fn set_error_message(&mut self, error: impl Into<Error>)
Sets the error message.
sourcepub fn set_json_data(&mut self, data: impl Into<JsonValue>)
pub fn set_json_data(&mut self, data: impl Into<JsonValue>)
Sets the JSON data.
sourcepub fn set_bytes_data(&mut self, data: impl Into<Bytes>)
pub fn set_bytes_data(&mut self, data: impl Into<Bytes>)
Sets the bytes data.
sourcepub fn set_validation_data(&mut self, validation: Validation)
pub fn set_validation_data(&mut self, validation: Validation)
Sets the response data for the validation.
sourcepub fn set_data_transformer(&mut self, transformer: DataTransformer)
pub fn set_data_transformer(&mut self, transformer: DataTransformer)
Sets a transformer for the response data.
sourcepub fn set_content_type(&mut self, content_type: impl Into<SharedString>)
pub fn set_content_type(&mut self, content_type: impl Into<SharedString>)
Sets the content type.
Note
Currently, we have built-in support for the following values:
application/jsonapplication/jsonlinesapplication/msgpackapplication/octet-streamapplication/problem+jsonapplication/x-www-form-urlencodedtext/csvtext/htmltext/plain
sourcepub fn set_form_response(&mut self, data: impl Into<JsonValue>)
pub fn set_form_response(&mut self, data: impl Into<JsonValue>)
Sets the form data as the response body.
sourcepub fn set_json_response(&mut self, data: impl Into<JsonValue>)
pub fn set_json_response(&mut self, data: impl Into<JsonValue>)
Sets the JSON data as the response body.
sourcepub fn set_jsonlines_response(&mut self, data: impl Into<JsonValue>)
pub fn set_jsonlines_response(&mut self, data: impl Into<JsonValue>)
Sets the JSON Lines data as the response body.
sourcepub fn set_msgpack_response(&mut self, data: impl Into<JsonValue>)
pub fn set_msgpack_response(&mut self, data: impl Into<JsonValue>)
Sets the MsgPack data as the response body.
sourcepub fn set_csv_response(&mut self, data: impl Into<JsonValue>)
pub fn set_csv_response(&mut self, data: impl Into<JsonValue>)
Sets the CSV data as the response body.
sourcepub fn set_text_response(&mut self, data: impl Into<String>)
pub fn set_text_response(&mut self, data: impl Into<String>)
Sets the plain text as the response body.
sourcepub fn set_bytes_response(&mut self, data: impl Into<Bytes>)
pub fn set_bytes_response(&mut self, data: impl Into<Bytes>)
Sets the bytes data as the response body.
Sends a cookie to the user agent.
sourcepub fn record_server_timing(
&mut self,
name: impl Into<SharedString>,
description: Option<SharedString>,
duration: Option<Duration>
)
pub fn record_server_timing( &mut self, name: impl Into<SharedString>, description: Option<SharedString>, duration: Option<Duration> )
Records a server timing metric entry.
sourcepub fn insert_header(
&mut self,
name: impl Into<SharedString>,
value: impl ToString
)
pub fn insert_header( &mut self, name: impl Into<SharedString>, value: impl ToString )
Inserts a custom header.
sourcepub fn get_header(&self, name: &str) -> Option<&str>
pub fn get_header(&self, name: &str) -> Option<&str>
Gets a custome header with the given name.
sourcepub fn status_code(&self) -> u16
pub fn status_code(&self) -> u16
Returns the status code as u16.
sourcepub fn error_code(&self) -> Option<&S::ErrorCode>
pub fn error_code(&self) -> Option<&S::ErrorCode>
Returns the error code.
sourcepub fn business_code(&self) -> Option<&S::BusinessCode>
pub fn business_code(&self) -> Option<&S::BusinessCode>
Returns the business code.
sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns true if the response is successful or false otherwise.
sourcepub fn has_context(&self) -> bool
pub fn has_context(&self) -> bool
Returns true if the response has a request context.
sourcepub fn request_id(&self) -> Uuid
pub fn request_id(&self) -> Uuid
Returns the request ID.
sourcepub fn content_type(&self) -> &str
pub fn content_type(&self) -> &str
Returns the content type.
sourcepub fn headers(&self) -> &[(SharedString, String)]
pub fn headers(&self) -> &[(SharedString, String)]
Returns the custom headers.
sourcepub fn trace_context(&self) -> (String, String)
pub fn trace_context(&self) -> (String, String)
Returns the trace context in the form (traceparent, tracestate).
sourcepub fn server_timing(&self) -> String
pub fn server_timing(&self) -> String
Returns the server timing.
sourcepub fn read_bytes(&mut self) -> Result<Bytes, Error>
pub fn read_bytes(&mut self) -> Result<Bytes, Error>
Reads the response into a byte buffer.
sourcepub fn response_time(&self) -> Duration
pub fn response_time(&self) -> Duration
sourcepub fn finalize(self) -> impl Iterator<Item = (SharedString, String)>
pub fn finalize(self) -> impl Iterator<Item = (SharedString, String)>
Consumes self and returns the custom headers.
Trait Implementations§
source§impl<S: ResponseCode> Default for Response<S>
impl<S: ResponseCode> Default for Response<S>
source§impl<S: ResponseCode> From<Response<S>> for FullResponse
impl<S: ResponseCode> From<Response<S>> for FullResponse
source§impl<S: ResponseCode> From<Validation> for Response<S>
impl<S: ResponseCode> From<Validation> for Response<S>
source§fn from(validation: Validation) -> Self
fn from(validation: Validation) -> Self
Auto Trait Implementations§
impl<S> RefUnwindSafe for Response<S>where
S: RefUnwindSafe,
<S as ResponseCode>::BusinessCode: RefUnwindSafe,
<S as ResponseCode>::ErrorCode: RefUnwindSafe,
impl<S> Send for Response<S>
impl<S> Sync for Response<S>
impl<S> Unpin for Response<S>
impl<S> UnwindSafe for Response<S>where
S: UnwindSafe,
<S as ResponseCode>::BusinessCode: UnwindSafe,
<S as ResponseCode>::ErrorCode: 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
§impl<T> Conv for T
impl<T> Conv for T
§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
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>
§impl<T, U, I> LiftInto<U, I> for Twhere
U: LiftFrom<T, I>,
impl<T, U, I> LiftInto<U, I> for Twhere
U: LiftFrom<T, I>,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<Source> Sculptor<HNil, HNil> for Source
impl<Source> Sculptor<HNil, HNil> for Source
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.