pub struct Response {
pub http_version: String,
pub status_code: i16,
pub reason_phrase: String,
pub headers: Vec<Header>,
pub content_range_list: Vec<ContentRange>,
pub stream_file: Option<String>,
pub stream_pipe: Option<Box<dyn Read + Send>>,
}Expand description
An HTTP response. Build one inside [Controller::process] and return it.
Set status_code and reason_phrase from STATUS_CODE_REASON_PHRASE,
push body content via Range::get_content_range into content_range_list,
and add any extra headers to headers.
For large files, set stream_file to the absolute file path instead of loading
the body into content_range_list. The server will stream it with
Transfer-Encoding: chunked so memory usage stays constant regardless of file size.
For proxy passthrough (SSE, AI token streams, large downloads), set stream_pipe
to a boxed Read source instead. The server streams its output with
Transfer-Encoding: chunked immediately after sending the response headers.
Fields§
§http_version: StringHTTP version string, e.g. "HTTP/1.1".
status_code: i16Numeric status code, e.g. 200. Set from STATUS_CODE_REASON_PHRASE.
reason_phrase: StringReason phrase, e.g. "OK". Set from STATUS_CODE_REASON_PHRASE.
headers: Vec<Header>Response headers. Pre-populated with standard headers by Header::get_header_list.
content_range_list: Vec<ContentRange>Response body as a list of content ranges (supports multipart and range responses).
stream_file: Option<String>If set, the server streams this file with Transfer-Encoding: chunked
instead of using content_range_list. Use for files larger than ~8 MB.
stream_pipe: Option<Box<dyn Read + Send>>If set, the server pipes bytes from this reader with Transfer-Encoding: chunked
immediately after sending the response headers. Takes precedence over
content_range_list and stream_file. The reader is consumed and not cloned.
Implementations§
Source§impl Response
impl Response
pub const _ERROR_UNABLE_TO_PARSE_HTTP_VERSION_STATUS_CODE: &'static str = "Unable to parse status code"
pub const _HTTP_VERSION_AND_STATUS_CODE_AND_REASON_PHRASE_REGEX: &'static str = "(?P<http_version>\\w+/\\w+.\\w)\\s(?P<status_code>\\w+)\\s(?P<reason_phrase>.+)"
pub fn build( status: StatusCodeReasonPhrase, header_list: Vec<Header>, body: Vec<ContentRange>, ) -> Response
pub fn status_code_reason_phrase_list() -> Vec<&'static StatusCodeReasonPhrase>
pub fn _get_header(&self, name: String) -> Option<&Header>
pub fn generate_body(content_range_list: Vec<ContentRange>) -> Vec<u8> ⓘ
pub fn generate_response(response: Response, request: Request) -> Vec<u8> ⓘ
pub fn _parse_response(response_vec_u8: &[u8]) -> Response
pub fn _parse_http_version_status_code_reason_phrase_string( http_version_status_code_reason_phrase: &str, ) -> Result<(String, i16, String), String>
pub fn _parse_http_response_header_string(header_string: &str) -> Header
pub fn _parse_raw_response_via_cursor( cursor: &mut Cursor<&[u8]>, iteration_number: usize, response: &mut Response, content_length: usize, )
pub fn _is_multipart_byteranges_content_type(content_type: &Header) -> bool
pub fn get_response( status_code_reason_phrase: &StatusCodeReasonPhrase, boxed_header_list: Option<Vec<Header>>, boxed_content_range_list: Option<Vec<ContentRange>>, ) -> Response
pub fn generate(&mut self) -> Vec<u8> ⓘ
pub fn get_header(&self, name: String) -> Option<&Header>
pub fn parse(response_vec_u8: &[u8]) -> Result<Response, String>
pub fn parse_raw_response_via_cursor( cursor: &mut Cursor<&[u8]>, iteration_number: usize, response: &mut Response, content_length: usize, total_bytes: i32, bytes_read: i32, ) -> Result<(), String>
pub fn parse_http_response_header_string( header_string: &str, ) -> Result<Header, String>
Trait Implementations§
impl Eq for Response
Source§impl IntoResponse for Response
impl IntoResponse for Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl !RefUnwindSafe for Response
impl !Sync for Response
impl !UnwindSafe for Response
impl Freeze for Response
impl Send for Response
impl Unpin for Response
impl UnsafeUnpin for Response
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.