Skip to content

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

Merged
merged 6 commits into from
May 3, 2021
Merged

Implement redirect (#5) #30

merged 6 commits into from
May 3, 2021

Conversation

AkiaCode
Copy link
Member

@AkiaCode AkiaCode commented May 2, 2021

closes: #5

Copy link
Contributor

@corona10 corona10 left a 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.

Copy link
Contributor

@corona10 corona10 left a 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

Copy link
Contributor

@corona10 corona10 left a 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?

@corona10 corona10 requested a review from youknowone May 2, 2021 14:37
rust/src/lib.rs Outdated
Comment on lines 203 to 206
let redirect = headers.get("location").map(|url| request(url));
if redirect.is_some() {
return redirect.unwrap();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

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()

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert_eq!(body.len() > 0, true);
assert!(header.contains_key("content-type"));
assert!(!body.is_empty());

@corona10 corona10 merged commit c564909 into rust-kr:master May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

ch1: Implement redirect
3 participants