Merge pull request #9 from FauxFaux/close_notify
Map CloseNotify to EOF
This commit is contained in:
@@ -4,6 +4,9 @@ use std::net::TcpStream;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::time::Duration;
|
||||
|
||||
use rustls::StreamOwned;
|
||||
use rustls::ClientSession;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::unit::Unit;
|
||||
|
||||
@@ -58,7 +61,7 @@ impl Read for Stream {
|
||||
match self {
|
||||
Stream::Http(sock) => sock.read(buf),
|
||||
#[cfg(feature = "tls")]
|
||||
Stream::Https(stream) => stream.read(buf),
|
||||
Stream::Https(stream) => read_https(stream, buf),
|
||||
Stream::Cursor(read) => read.read(buf),
|
||||
#[cfg(test)]
|
||||
Stream::Test(reader, _) => reader.read(buf),
|
||||
@@ -66,6 +69,28 @@ impl Read for Stream {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_https(stream: &mut StreamOwned<ClientSession, TcpStream>, buf: &mut [u8]) -> IoResult<usize> {
|
||||
match stream.read(buf) {
|
||||
Ok(size) => Ok(size),
|
||||
Err(ref e) if is_close_notify(e) => Ok(0),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_close_notify(e: &std::io::Error) -> bool {
|
||||
if e.kind() != std::io::ErrorKind::ConnectionAborted {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(msg) = e.get_ref() {
|
||||
// :(
|
||||
|
||||
return msg.description().contains("CloseNotify");
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
impl Write for Stream {
|
||||
fn write(&mut self, buf: &[u8]) -> IoResult<usize> {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user