aboutsummaryrefslogtreecommitdiff
path: root/src/request.rs
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2024-06-05 19:10:30 +0300
committeromagdy7 <omar.professional8777@gmail.com>2024-06-05 19:10:30 +0300
commit07c54da628ec776627e68c25196539389c8d965c (patch)
tree30255789673c09d4a74e8372796f8ba4988cf4f4 /src/request.rs
parentff75fa542a98cf9a79133a81b7716401e717bfd6 (diff)
downloadtiny-server-07c54da628ec776627e68c25196539389c8d965c.tar.xz
tiny-server-07c54da628ec776627e68c25196539389c8d965c.zip
codecrafters submit [skip ci]
Diffstat (limited to 'src/request.rs')
-rw-r--r--src/request.rs10
1 files changed, 9 insertions, 1 deletions
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<Vec<&str>> 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::<usize>()
+ .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!();