Skip to content

Commit

Permalink
Reserve enough space for ServerError task to write status line
Browse files Browse the repository at this point in the history
  • Loading branch information
DoumanAsh committed Aug 7, 2018
1 parent 9c80d3a commit 86a5afb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/server/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ impl HttpHandlerTask for ServerError {
fn poll_io(&mut self, io: &mut Writer) -> Poll<bool, Error> {
{
let bytes = io.buffer();
//Buffer should have sufficient capacity for status line
//and extra space
bytes.reserve(helpers::STATUS_LINE_BUF_SIZE + 1);
helpers::write_status_line(self.0, self.1.as_u16(), bytes);
}
io.set_date();
Expand Down
4 changes: 3 additions & 1 deletion src/server/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ const DEC_DIGITS_LUT: &[u8] = b"0001020304050607080910111213141516171819\
6061626364656667686970717273747576777879\
8081828384858687888990919293949596979899";

pub(crate) const STATUS_LINE_BUF_SIZE: usize = 13;

pub(crate) fn write_status_line(version: Version, mut n: u16, bytes: &mut BytesMut) {
let mut buf: [u8; 13] = [
let mut buf: [u8; STATUS_LINE_BUF_SIZE] = [
b'H', b'T', b'T', b'P', b'/', b'1', b'.', b'1', b' ', b' ', b' ', b' ', b' ',
];
match version {
Expand Down

0 comments on commit 86a5afb

Please sign in to comment.