diff --git a/src/main.rs b/src/main.rs index 6294cc5..7281154 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ -#![feature(if_let_guard)] +// #![feature(if_let_guard)] -use std::{ fmt::Display, io::{ BufRead, BufReader, Write }, net::TcpListener }; +use std::{ io::{ BufRead, BufReader, Write }, net::TcpListener }; use anyhow::Result; use thiserror::Error; @@ -30,15 +30,16 @@ fn main() -> Result<()> { let start_line = data.next().ok_or(E::InvalidRequest)?; // should be 500; let mut parts = start_line.split_whitespace().map(ToOwned::to_owned); let method = parts.next().ok_or(E::InvalidRequest)?; - let path = parts.next().ok_or(E::InvalidRequest)?; - let ver = parts.next().ok_or(E::InvalidRequest)?; + let path = parts.next().ok_or(E::InvalidRequest)?; + let ver = parts.next().ok_or(E::InvalidRequest)?; (method, path, ver) }; let response = match path.as_str() { "/" => Response::Empty, - p if let Some(echo) = p.strip_prefix("/echo/") => Response::TextPlain(echo), + // p if let Some(echo) = p.strip_prefix("/echo/") => Response::TextPlain(echo), // a nicer way to do that, not available in stable yet + p if p.starts_with("/echo/") => Response::TextPlain(p.trim_start_matches("/echo/")), _ => Response::_404, };