@@ -109,8 +109,6 @@ impl<'a, W: Any> Response<'a, W> {
|
||||
|
||||
Ok(body_type)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
impl<'a> Response<'a, Fresh> {
|
||||
@@ -126,6 +124,23 @@ impl<'a> Response<'a, Fresh> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes the body and ends the response.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use hyper::server::Response;
|
||||
/// fn handler(res: Response) {
|
||||
/// res.send(b"Hello World!").unwrap();
|
||||
/// }
|
||||
/// ```
|
||||
pub fn send(mut self, body: &[u8]) -> io::Result<()> {
|
||||
self.headers.set(header::ContentLength(body.len() as u64));
|
||||
let mut stream = try!(self.start());
|
||||
try!(stream.write_all(body));
|
||||
stream.end()
|
||||
}
|
||||
|
||||
/// Consume this Response<Fresh>, writing the Headers and Status and creating a Response<Streaming>
|
||||
pub fn start(mut self) -> io::Result<Response<'a, Streaming>> {
|
||||
let body_type = try!(self.write_head());
|
||||
|
||||
Reference in New Issue
Block a user