-
Notifications
You must be signed in to change notification settings - Fork 9
Implement redirect (#5) #30
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
Conversation
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.
assert status == "200", f"{status}: {explanation}"
also should be changed.
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.
we may able to support 302 status also and add test code with http://www.naver.com
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.
lgtm
@youknowone Can you please take a look Rust code?
rust/src/lib.rs
Outdated
let redirect = headers.get("location").map(|url| request(url)); | ||
if redirect.is_some() { | ||
return redirect.unwrap(); | ||
} |
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.
let redirect = headers.get("location").map(|url| request(url)); | |
if redirect.is_some() { | |
return redirect.unwrap(); | |
} | |
if let Some(redirect) = headers.get("location").map(request) { | |
return redirect; | |
} |
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.
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.
Then, map(|url| request(url)
please. The major goal is removnig unnessessary is_some()
and unwrap()
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.
I now think request part must be in the body of the if block because request is a failable function in theory - though we are not handling it here. So a new suggestion is:
if let Some(url) = headers.get("location") {
return request(url);
}
this is also equivalent to the python version.
rust/src/lib.rs
Outdated
for site in redirect_sites { | ||
let (header, body) = http::request(site).unwrap(); | ||
assert_eq!(header.contains_key("content-type"), true); | ||
assert_eq!(body.len() > 0, true); |
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.
assert_eq!(body.len() > 0, true); | |
assert!(header.contains_key("content-type")); | |
assert!(!body.is_empty()); |
closes: #5