From a86efcf494c818862654383006457648035bb8a4 Mon Sep 17 00:00:00 2001 From: YK Date: Fri, 10 May 2024 21:37:00 +0300 Subject: [PATCH] stage 4 attempt 2 --- src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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, };