Move BufReader up the stack in Stream.
Stream now has an `Inner` enum, and wraps an instance of that enum in a BufReader. This allows Stream itself to implement BufRead trivially, and simplify some of the match dispatching. Having Stream implement BufRead means we can make use of `read_line` instead of our own `read_next_line` (not done in this PR yet). Also, removes the `Cursor` variant of the Inner enum in favor of using the `Test` variant everywhere, since it's strictly more powerful.
This commit is contained in:
@@ -3,7 +3,7 @@ use crate::stream::Stream;
|
||||
use crate::unit::Unit;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::HashMap;
|
||||
use std::io::{Cursor, Write};
|
||||
use std::io::Write;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
mod agent_test;
|
||||
@@ -29,7 +29,7 @@ where
|
||||
}
|
||||
|
||||
#[allow(clippy::write_with_newline)]
|
||||
pub fn make_response(
|
||||
pub(crate) fn make_response(
|
||||
status: u16,
|
||||
status_text: &str,
|
||||
headers: Vec<&str>,
|
||||
@@ -42,9 +42,7 @@ pub fn make_response(
|
||||
}
|
||||
write!(&mut buf, "\r\n").ok();
|
||||
buf.append(&mut body);
|
||||
let cursor = Cursor::new(buf);
|
||||
let write: Vec<u8> = vec![];
|
||||
Ok(Stream::Test(Box::new(cursor), write))
|
||||
Ok(Stream::from_vec(buf))
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_handler(unit: &Unit) -> Result<Stream, Error> {
|
||||
|
||||
Reference in New Issue
Block a user