-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring HTTP #11
Refactoring HTTP #11
Conversation
Hello. Thank you for the PR, I'll drop some notes on it. |
src/server.rs
Outdated
@@ -39,7 +40,7 @@ impl Server { | |||
|
|||
pub fn build_http_request(mut stream: TcpStream) -> (TcpStream, Request) { | |||
let (request, body) = parse_tcp_stream(&mut stream); | |||
let request = parse_http_string((request, body)); | |||
let request = Request::from_str(&request).unwrap().body(body).clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing from_str is a good idea.
However, this
(&request).unwrap().body(body).clone();
is why I don't like chainable methods.
I feel like it's hurting readability here.
IMO the previous code is a bit better, and a bit more abstract, instead of passing a reference then unwrapping then calling another method to set the body then cloning.
Maybe a good middle ground is implementing a method on the struct like what parse_http_string is doing and having it construct the struct with the body.
I think an even better solution would be implementing parse_tcp_stream on the Request struct, after all, it is related to it, and it's also the only thing using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chainable methods is needed here, You can't passing any arguments other than string that you want parse, So It's important here and unavoidable (Unless there is a way that I don't know) if we want use from_str
src/http/methods.rs
Outdated
PATCH, | ||
DELETE, | ||
HEAD, | ||
OPTIONS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it really need its own file? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https.rs was crowded with many things. Frankly, I like organization and I do not see that there is a problem with a large number of files, but everything is organized.
Maybe in future you can add Http status codes enum here, But the difficulty will be in naming the file :D
src/http/mod.rs
Outdated
true => { | ||
self.headers.insert( | ||
"Content-Type".to_string(), | ||
"multipart/form-data".to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, not particularly fond of chainable methods.
Thanks for the PR! |
What's new?