cookie jar
This commit is contained in:
@@ -7,7 +7,18 @@ use std::net::TcpStream;
|
||||
pub enum Stream {
|
||||
Http(TcpStream),
|
||||
Https(rustls::ClientSession, TcpStream),
|
||||
#[cfg(test)] Test(Box<Read + Send>, Box<Write + Send>),
|
||||
Read(Box<Read>),
|
||||
#[cfg(test)] Test(Box<Read + Send>, Vec<u8>),
|
||||
}
|
||||
|
||||
impl Stream {
|
||||
#[cfg(test)]
|
||||
pub fn to_write_vec(&self) -> Vec<u8> {
|
||||
match self {
|
||||
Stream::Test(_, writer) => writer.clone(),
|
||||
_ => panic!("to_write_vec on non Test stream")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Read for Stream {
|
||||
@@ -15,6 +26,7 @@ impl Read for Stream {
|
||||
match self {
|
||||
Stream::Http(sock) => sock.read(buf),
|
||||
Stream::Https(sess, sock) => rustls::Stream::new(sess, sock).read(buf),
|
||||
Stream::Read(read) => read.read(buf),
|
||||
#[cfg(test)] Stream::Test(reader, _) => reader.read(buf),
|
||||
}
|
||||
}
|
||||
@@ -25,6 +37,7 @@ impl Write for Stream {
|
||||
match self {
|
||||
Stream::Http(sock) => sock.write(buf),
|
||||
Stream::Https(sess, sock) => rustls::Stream::new(sess, sock).write(buf),
|
||||
Stream::Read(_) => panic!("Write to read stream"),
|
||||
#[cfg(test)] Stream::Test(_, writer) => writer.write(buf),
|
||||
}
|
||||
}
|
||||
@@ -32,6 +45,7 @@ impl Write for Stream {
|
||||
match self {
|
||||
Stream::Http(sock) => sock.flush(),
|
||||
Stream::Https(sess, sock) => rustls::Stream::new(sess, sock).flush(),
|
||||
Stream::Read(_) => panic!("Flush read stream"),
|
||||
#[cfg(test)] Stream::Test(_, writer) => writer.flush(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user