initial commit

This commit is contained in:
Martin Algesten
2017-12-12 04:40:30 +01:00
parent f1b9318994
commit 4df9876c24
15 changed files with 2475 additions and 5 deletions

34
src/stream.rs Normal file
View File

@@ -0,0 +1,34 @@
use rustls;
use std::io::Read;
use std::io::Result;
use std::io::Write;
use std::net::TcpStream;
pub enum Stream {
Http(TcpStream),
Https(rustls::ClientSession, TcpStream),
}
impl Read for Stream {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
match self {
Stream::Http(sock) => sock.read(buf),
Stream::Https(sess, sock) => rustls::Stream::new(sess, sock).read(buf),
}
}
}
impl Write for Stream {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
match self {
Stream::Http(sock) => sock.write(buf),
Stream::Https(sess, sock) => rustls::Stream::new(sess, sock).write(buf),
}
}
fn flush(&mut self) -> Result<()> {
match self {
Stream::Http(sock) => sock.flush(),
Stream::Https(sess, sock) => rustls::Stream::new(sess, sock).flush(),
}
}
}