2018-06-25 06:58:04 +02:00
|
|
|
use futures::{Async, Poll};
|
|
|
|
|
|
|
|
use super::{helpers, HttpHandlerTask, Writer};
|
|
|
|
use http::{StatusCode, Version};
|
|
|
|
use Error;
|
|
|
|
|
|
|
|
pub(crate) struct ServerError(Version, StatusCode);
|
|
|
|
|
|
|
|
impl ServerError {
|
|
|
|
pub fn err(ver: Version, status: StatusCode) -> Box<HttpHandlerTask> {
|
|
|
|
Box::new(ServerError(ver, status))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HttpHandlerTask for ServerError {
|
|
|
|
fn poll_io(&mut self, io: &mut Writer) -> Poll<bool, Error> {
|
|
|
|
{
|
2018-07-04 17:01:27 +02:00
|
|
|
let bytes = io.buffer();
|
2018-08-07 20:56:39 +02:00
|
|
|
// Buffer should have sufficient capacity for status line
|
|
|
|
// and extra space
|
2018-08-07 16:33:49 +02:00
|
|
|
bytes.reserve(helpers::STATUS_LINE_BUF_SIZE + 1);
|
2018-06-25 06:58:04 +02:00
|
|
|
helpers::write_status_line(self.0, self.1.as_u16(), bytes);
|
|
|
|
}
|
2018-09-01 11:00:32 +02:00
|
|
|
// Convert Status Code to Reason.
|
|
|
|
let reason = self.1.canonical_reason().unwrap_or("");
|
|
|
|
io.buffer().extend_from_slice(reason.as_bytes());
|
|
|
|
// No response body.
|
2018-08-07 20:56:39 +02:00
|
|
|
io.buffer().extend_from_slice(b"\r\ncontent-length: 0\r\n");
|
2018-09-01 11:00:32 +02:00
|
|
|
// date header
|
2018-06-25 06:58:04 +02:00
|
|
|
io.set_date();
|
|
|
|
Ok(Async::Ready(true))
|
|
|
|
}
|
|
|
|
}
|