~garritfra/taurus

6fe4a2d026508b0307272b966685cec757766fe0 — Alexey Yerin 4 years ago 9c83ef8
Cancel request on invalid Unicode character

It's pointless to continue as file names mostly don't contain invalid
Unicode.

Signed-off-by: Alexey Yerin <yerinalexey98fd@gmail.com>
2 files changed, 4 insertions(+), 1 deletions(-)

M src/error.rs
M src/main.rs
M src/error.rs => src/error.rs +3 -0
@@ 17,6 17,9 @@ pub enum TaurusError {
    #[error("invalid request: {0}")]
    InvalidRequest(String),

    #[error("invalid Unicode character in the input")]
    InvalidUnicode(#[from] std::string::FromUtf8Error),

    #[error("failed to bind: {0}")]
    BindFailed(io::Error),


M src/main.rs => src/main.rs +1 -1
@@ 99,7 99,7 @@ fn handle_client(mut stream: TlsStream<TcpStream>, static_root: &str) -> TaurusR
        .read(&mut buffer)
        .map_err(TaurusError::StreamReadFailed)?;

    let raw_request = String::from_utf8_lossy(&buffer[..]).into_owned();
    let raw_request = String::from_utf8(buffer.to_vec())?;

    let request = GeminiRequest::parse(&raw_request)?;
    let url_path = request.file_path();