pub struct Response {
pub kind: ResponseKind,
pub code: u16,
pub content_type: ContentType,
pub headers: HeaderList,
pub body: ResponseBody,
}Fields§
§kind: ResponseKind§code: u16§content_type: ContentType§headers: HeaderList§body: ResponseBodyImplementations§
Source§impl Response
impl Response
pub fn new(code: u16) -> Self
Sourcepub fn drop_connection() -> Self
pub fn drop_connection() -> Self
Return this and the server will drop the connection.
Sourcepub fn get_body_and_reprocess(max_len: u64) -> Self
pub fn get_body_and_reprocess(max_len: u64) -> Self
Return this and the server will read the request body from the client and call the request handler again.
If the request body is larger than max_len bytes, it sends 413 Payload Too Large.
pub fn html(code: u16, body: impl Into<ResponseBody>) -> Self
pub fn event_stream() -> (EventSender, Response)
pub fn text(code: u16, body: impl Into<ResponseBody>) -> Self
pub fn ok_200() -> Self
pub fn no_content_204() -> Self
Sourcepub fn redirect_301(location: impl AsRef<str>) -> Self
pub fn redirect_301(location: impl AsRef<str>) -> Self
Tell the client to GET location.
The client should store this redirect.
§Panics
Panics when location is not US-ASCII.
Sourcepub fn redirect_303(location: impl AsRef<str>) -> Self
pub fn redirect_303(location: impl AsRef<str>) -> Self
Tell the client to GET location.
The client should not store this redirect.
A PUT or POST handler usually returns this.
§Panics
Panics when location is not US-ASCII.
pub fn forbidden_403() -> Self
pub fn not_found_404() -> Self
Sourcepub fn method_not_allowed_405(allowed_methods: &[&'static str]) -> Self
pub fn method_not_allowed_405(allowed_methods: &[&'static str]) -> Self
§Panics
Panics when any of allowed_methods are not US-ASCII.
pub fn length_required_411() -> Self
pub fn payload_too_large_413() -> Self
pub fn unprocessable_entity_422(body: impl Into<String>) -> Self
pub fn too_many_requests_429() -> Self
pub fn internal_server_error_500() -> Self
pub fn not_implemented_501() -> Self
pub fn with_body(self, b: impl Into<ResponseBody>) -> Self
Sourcepub fn with_max_age_seconds(self, seconds: u32) -> Self
pub fn with_max_age_seconds(self, seconds: u32) -> Self
Adds a Cache-Control: max-age=N header.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
Sourcepub fn with_no_store(self) -> Self
pub fn with_no_store(self) -> Self
Adds a Cache-Control: no-store header.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
Adds a Set-Cookie header.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
Sourcepub fn with_header(self, name: impl AsRef<str>, value: AsciiString) -> Self
pub fn with_header(self, name: impl AsRef<str>, value: AsciiString) -> Self
Adds a header.
You can call this multiple times to add multiple headers with the same name.
The HTTP spec limits header names to US-ASCII and header values to US-ASCII or ISO-8859-1.
§Panics
Panics when name is not US-ASCII.
§Example
use servlin::Response;
return Response::new(200)
.with_header("header1", "value1".to_string().try_into().unwrap());