Skip to content

feat: show redirects & remaps#2094

Merged
thomas-zahner merged 11 commits intolycheeverse:masterfrom
thomas-zahner:remap-improve-ux
Mar 31, 2026
Merged

feat: show redirects & remaps#2094
thomas-zahner merged 11 commits intolycheeverse:masterfrom
thomas-zahner:remap-improve-ux

Conversation

@thomas-zahner
Copy link
Copy Markdown
Member

@thomas-zahner thomas-zahner commented Mar 20, 2026

Fixes #1493
Fixes #2011

Please take a look a the commit messages for more details.

Example

Running echo 'http://github.com/lycheeverse/lychee' | cargo run - --remap 'github gitlab' will now yield:

Issues found in 1 input. Find details below.

[stdin]:
   [403] http://gitlab.com/lycheeverse/lychee (at 1:1) | Rejected status code: 403 Forbidden (configurable with "accept" option) | Remapped: http://github.com/lycheeverse/lychee --> http://gitlab.com/lycheeverse/lychee) | Followed 2 redirects. Redirects: http://gitlab.com/lycheeverse/lychee --[301]--> https://gitlab.com/lycheeverse/lychee --[302]--> https://gitlab.com/users/sign_in

🔍 1 Total (in 325ms) ✅ 0 OK 🚫 1 Error 🔀 1 Redirects

Notes

  • As visible in the above example, with the new nesting "Total" no longer adds up to "OK" + "Errors" + "Redirects" ... But I'm not really sure if this was the case previously.
  • Just noticed a dangling ) in the details "Remapped: A --> B)", will adjust and write a test to cover this. It's currently uncovered.

@thomas-zahner thomas-zahner force-pushed the remap-improve-ux branch 4 times, most recently from de5c60a to b0d9566 Compare March 20, 2026 17:09
@thomas-zahner thomas-zahner requested review from katrinafyi and mre March 20, 2026 17:17
@thomas-zahner thomas-zahner changed the title Remap improve ux feat: show redirects & remaps Mar 20, 2026
Copy link
Copy Markdown
Member

@katrinafyi katrinafyi left a comment

Choose a reason for hiding this comment

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

It looks reasonable and seems to do what it should. The biggest comment is about whether the remap history needs to/should be globally stored. I think it shouldn't.

In testing, I also noticed an interesting interaction with caching:

a.md:
[a](https://httpbin.org/delay/5)
[a](https://httpbin.org/delay/5)
$ cargo run -- a.md --max-concurrency=1 --remap 'httpbin nowherejiosad'  
[a.md]:
 [ERROR] https://httpbin.org/delay/5 (at 2:1) | Error (cached)
 [ERROR] https://nowherejiosad.org/delay/5 (at 1:1) | Connection failed. Check network connectivity and firewall settings | Remapped: https://httpbin.org/delay/5 --> https://nowherejiosad.org/delay/5)

The remap is only printed for the non-cached run, and the cache hits have the old URL and no remap history. This makes sense, given the caching strategy, but it is a bit odd. But this also isn't new in this PR - on main, it's identical but for the "Remapped:" text so no need to change here.

It is also possible to remap URLs into excluded URLs. With -v, the excluded URLs are printed but they don't have redirect information. I think the [EXCLUDED] message uses the same formatter as the CLI output, so it would be nice to have remaps mentioned here as well.

$ cargo  run -- a.md --max-concurrency=1 --remap 'httpbin nowherejiosad'   --exclude nowherejiosad -v          
[EXCLUDED] https://nowherejiosad.org/delay/5 (at 1:1) | This is due to your 'exclude' and 'include' values
[EXCLUDED] https://nowherejiosad.org/delay/5 (at 2:1) | This is due to your 'exclude' and 'include' values
🔍 2 Total (in 2ms) ✅ 0 OK 🚫 0 Errors 👻 2 Excluded

@thomas-zahner thomas-zahner force-pushed the remap-improve-ux branch 2 times, most recently from 22d9df0 to d9aba65 Compare March 24, 2026 17:38
Copy link
Copy Markdown
Member

@katrinafyi katrinafyi left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks the fast changes! There's a smattering of comments, all just suggestions and very optional.

@thomas-zahner thomas-zahner force-pushed the remap-improve-ux branch 2 times, most recently from fe91a5a to a273181 Compare March 25, 2026 10:01
@thomas-zahner
Copy link
Copy Markdown
Member Author

In testing, I also noticed an interesting interaction with caching:

That's interesting. If the status is really loaded from the disk's cache I think it would be expected behaviour. But thinking about this specific case, I'm not sure this should happen at all. See #2103

I also realised that the redirect_map became useless in the process, as it was no longer a "terminal" status code. See a2b72ec

Copy link
Copy Markdown
Member

@mre mre left a comment

Choose a reason for hiding this comment

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

I'm okay with merging this once CI is green. It's a solid improvement. The open discussion points aren't super critical afaict and we have issues to track those. Good work! 👍

@thomas-zahner thomas-zahner force-pushed the remap-improve-ux branch 2 times, most recently from a21c14a to d7d7bbe Compare March 27, 2026 16:30
The Redirected variant now has Box<Status> instead of a terminal
StatusCode. In practice this means that redirection details are shown
even when the status is considered erroneous.

Fixes lycheeverse#2011
Remaps are now tracked via the `RemapHistory` helper struct. This allows
us to embed the information in the newly added `Status::Remapped`
variant. Error logging and formatting has also been improved quite a
bit, removing redundant information and displaying more useful details
in some cases.
Remove unnecessary RemapHistory. Thanks @katrinafyi for the idea.
Use Uris instead of Urls.
Fix a bug where the original Uris were dumped instead of the remappings.
@thomas-zahner thomas-zahner merged commit 4bff560 into lycheeverse:master Mar 31, 2026
7 checks passed
@mre mre mentioned this pull request Mar 31, 2026
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.

Redirects aren't reported for rejected status codes Preserve original URLs when --remap is used

3 participants