Skip to content
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

[#270] Handle relative redirects #271

Merged
merged 1 commit into from
Jan 27, 2023
Merged

Conversation

aeqz
Copy link
Contributor

@aeqz aeqz commented Jan 26, 2023

Description

Problem: Currently, Xrefcheck can follow redirects with an absolute location link, but it cannot handle relative ones.

Solution: After parsing the location link, obtain the corresponding absolute link by using the original request one.

Related issue(s)

Fixes #270

Related changes (conditional)

  • Tests

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from
      silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:
  • Public contracts

    • Any modifications of public contracts comply with the Evolution
      of Public Contracts
      policy.
    • I added an entry to the changelog if my changes are visible to the users
      and
    • provided a migration guide for breaking changes if possible

Stylistic guide (mandatory)

Just nextLink -> do
nextUri <- ExternalResourceUriParseError `withExceptT` parseUri True nextLink
nextLinkAbsolute <- case relativeTo nextUri uri of
Nothing -> error "Not absolute URL exception"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should not happen because uri has been parsed with parseUri False.

Copy link
Member

Choose a reason for hiding this comment

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

I would put this explanation as code comment, it seems worthy.

Nothing -> throwError $ RedirectMissingLocation $ followed `pushRequest` RedirectChainLink link
Just nextLink -> do
nextUri <- ExternalResourceUriParseError `withExceptT` parseUri True nextLink
nextLinkAbsolute <- case relativeTo nextUri uri of
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mainly used the relativeTo function from the modern-uri package for this task. This is how we obtain the absolute target link from the (absolute) source + the (absolute or relative) target.

-- configurations of this type is 'strictURIParserOptions', which follows
-- RFC 3986, and the other -- 'laxURIParseOptions' -- allows brackets
-- in the queries, which draws us closer to the WHATWG URL standard.
uri <- case URIBS.parseURI URIBS.laxURIParserOptions (encodeUtf8 link) of
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The modern-uri package can parse an URI deciding if it is absolute or relative depending on the success or failure of the scheme parsing. In uri-bytestring, it has to be decided beforehand, resulting in different URI types.

Copy link
Member

@Martoon-00 Martoon-00 left a comment

Choose a reason for hiding this comment

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

Great, thanks for implementing it this soon.

@aeqz aeqz force-pushed the aeqz/#270-handle-relative-redirects branch from d2c778b to ac02933 Compare January 26, 2023 18:23
Problem: Currently, Xrefcheck can follow redirects with an absolute
location link, but it cannot handle relative ones.

Solution: After parsing the location link, obtain the corresponding
absolute link by using the original request one.
@aeqz aeqz force-pushed the aeqz/#270-handle-relative-redirects branch from ac02933 to 9c2ac77 Compare January 27, 2023 21:51
@aeqz aeqz merged commit 4a33023 into master Jan 27, 2023
@aeqz aeqz deleted the aeqz/#270-handle-relative-redirects branch January 27, 2023 22:06
@int-index int-index mentioned this pull request Dec 27, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle relative redirects
2 participants