From 86a5afb5ca6eb0ad41b105e30e604a4c1ea169f7 Mon Sep 17 00:00:00 2001 From: Douman Date: Tue, 7 Aug 2018 17:33:49 +0300 Subject: [PATCH] Reserve enough space for ServerError task to write status line --- src/server/error.rs | 3 +++ src/server/helpers.rs | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server/error.rs b/src/server/error.rs index b3c79a06..4c264bc1 100644 --- a/src/server/error.rs +++ b/src/server/error.rs @@ -16,6 +16,9 @@ impl HttpHandlerTask for ServerError { fn poll_io(&mut self, io: &mut Writer) -> Poll { { 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(); diff --git a/src/server/helpers.rs b/src/server/helpers.rs index 03bbc831..f7e030f2 100644 --- a/src/server/helpers.rs +++ b/src/server/helpers.rs @@ -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 {