From 07c54da628ec776627e68c25196539389c8d965c Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Wed, 5 Jun 2024 19:10:30 +0300 Subject: codecrafters submit [skip ci] --- src/request.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/request.rs') diff --git a/src/request.rs b/src/request.rs index 27a41f5..aed69e5 100644 --- a/src/request.rs +++ b/src/request.rs @@ -47,7 +47,15 @@ impl From> for Request { [request_line, headers @ .., body] => { let (method, headers, body) = (Method::from(*request_line), Headers::from(headers), body); - Request::new(method, headers, (*body).to_string()) + if let Some(content_length) = headers.0.get("Content-Length") { + println!("Well hello there"); + let content_length = content_length + .parse::() + .expect("Content-Length should be parsable to usize"); + Request::new(method, headers, (body[0..content_length]).to_string()) + } else { + Request::new(method, headers, (*body).to_string()) + } } _ => { unreachable!(); -- cgit v1.2.3