pub struct Response {
pub status: u16,
pub headers: Vec<(String, String)>,
pub body: Vec<u8>,
pub stream: Option<Arc<Mutex<Option<StreamFn>>>>,
pub upgrade: Option<Arc<Mutex<Option<UpgradeFn>>>>,
}Fields§
§status: u16§headers: Vec<(String, String)>§body: Vec<u8>§stream: Option<Arc<Mutex<Option<StreamFn>>>>When set, written after the headers in place of body.
upgrade: Option<Arc<Mutex<Option<UpgradeFn>>>>When set, the status is 101 and this takes the connection over.
Implementations§
Source§impl Response
impl Response
pub fn new(status: u16) -> Self
Sourcepub fn upgrade(protocol: &str, f: UpgradeFn) -> Self
pub fn upgrade(protocol: &str, f: UpgradeFn) -> Self
101 Switching Protocols to protocol, then f owns the connection.
Sourcepub fn stream(status: u16, content_type: &str, f: StreamFn) -> Self
pub fn stream(status: u16, content_type: &str, f: StreamFn) -> Self
A streamed response: f writes the body and the connection closes
when it returns.
pub fn json(status: u16, v: &Value) -> Self
pub fn text(status: u16, s: &str) -> Self
pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn body(self, body: impl Into<Vec<u8>>) -> Self
pub fn get_header(&self, name: &str) -> Option<&str>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnsafeUnpin for Response
impl UnwindSafe 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
Mutably borrows from an owned value. Read more