pub struct ForgeResponse {
pub status: u16,
pub headers: Vec<(String, String)>,
pub body: Bytes,
}Expand description
Response returned from crate::ForgeService::handle; the server maps
it back to its native response type.
Fields§
§status: u16HTTP status code.
headers: Vec<(String, String)>Response headers as (name, value).
body: BytesBody bytes.
Implementations§
Source§impl ForgeResponse
impl ForgeResponse
Sourcepub fn with_type(
status: u16,
content_type: &str,
body: impl Into<Bytes>,
) -> Self
pub fn with_type( status: u16, content_type: &str, body: impl Into<Bytes>, ) -> Self
Build a response with a single content-type header.
Sourcepub fn html(status: u16, body: impl Into<String>) -> Self
pub fn html(status: u16, body: impl Into<String>) -> Self
Server-rendered HTML page. Callers must have esc()’d every
interpolated value.
Sourcepub fn json(status: u16, value: &Value) -> Self
pub fn json(status: u16, value: &Value) -> Self
JSON response. value is any serde_json::Value or serialisable.
Sourcepub fn raw_bytes(bytes: Bytes, is_text: bool, filename: &str) -> Self
pub fn raw_bytes(bytes: Bytes, is_text: bool, filename: &str) -> Self
Raw repository bytes served defensively: text blobs as
text/plain, everything else as an octet-stream attachment so
no browser ever renders repository content as markup.
Sourcepub fn error(status: u16, msg: impl Into<String>) -> Self
pub fn error(status: u16, msg: impl Into<String>) -> Self
A JSON {"error": msg} body at status.
Sourcepub fn with_header(self, name: &str, value: &str) -> Self
pub fn with_header(self, name: &str, value: &str) -> Self
Append a header (used for CORS on /blocktrails.json, etc.).
Trait Implementations§
Source§impl Clone for ForgeResponse
impl Clone for ForgeResponse
Source§fn clone(&self) -> ForgeResponse
fn clone(&self) -> ForgeResponse
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !Freeze for ForgeResponse
impl RefUnwindSafe for ForgeResponse
impl Send for ForgeResponse
impl Sync for ForgeResponse
impl Unpin for ForgeResponse
impl UnsafeUnpin for ForgeResponse
impl UnwindSafe for ForgeResponse
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