Skip to content

Commit

Permalink
Ignore ConnectionAborted error
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Ciber94 committed Sep 13, 2024
1 parent f0b6700 commit c12ab09
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
io::{BufRead, BufReader, Write},
io::{BufRead, BufReader, ErrorKind, Write},
net::{SocketAddr, TcpListener, TcpStream},
str::FromStr,
sync::{Arc, Mutex},
Expand Down Expand Up @@ -33,7 +33,11 @@ impl Server {
) {
let request = read_request(&mut stream).expect("Failed to read request");
let response = handler.handle(request);
write_response(response, &mut stream).unwrap()
match write_response(response, &mut stream) {
Ok(_) => {}
Err(err) if err.kind() == ErrorKind::ConnectionAborted => {}
Err(err) => eprintln!("{err}"),
}
}

pub fn listen<H: RequestHandler + Send + Sync + 'static>(
Expand Down Expand Up @@ -194,10 +198,5 @@ fn write_response(response: Response<Body>, stream: &mut TcpStream) -> std::io::
}
}

let last_bytes = body.read_last().map_err(std::io::Error::other)?;
if let Some(bytes) = last_bytes{
stream.write_all(&bytes)?;
}

Ok(())
}

0 comments on commit c12ab09

Please sign in to comment.