Read a reddit short or share link as the feed of the post it opens - #121
Merged
Merged
Conversation
fetchPage swaps a reddit.com page URL for its Atom feed, since the HTML page is a login wall for a reader with no cookies. It only looked at the URL as typed. A redd.it short link and the app's /r/<sub>/s/<code> share link are both a 301 to the post page, so the redirect landed on the wall and oc reported no readable content, while the post URL they point at reads fine. The swap now runs on every redirect hop too, through followRedirects, with the same rule: a logged-in session still gets the page. redd.it also joins the firefox-first hosts: the identity is picked once for the whole chain, and the reddit.com hop answers chrome with a 403, so starting with chrome spent two extra requests against reddit's rate limit on every short link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
oc openon a reddit short link or share link ends at the login wall, while the post URL it points at reads fine. Both are common in pasted links:redd.it/<id>short links, and the/r/<sub>/s/<code>links the reddit app's Share button makes.and
https://redd.it/1wsaolhon the branch, hop by hop:Cause.
fetchPage(src/fetch.js) swaps a reddit.com page URL for its Atom feed when the session has no reddit cookies (#52, #59), but only for the URL as typed. Both link shapes answer with a 301 to the post page, andfollowRedirectsfollowed that hop as is.Change.
readableURL(url, jar), used for the first URL as before and, through a newrewriteoption onfollowRedirects, for every redirect hop. Both transports pass it. The hop is rewritten beforeassertSafeTargetchecks it, so the check still sees the URL that is actually fetched. A session with reddit cookies still gets the page it asked for, on every hop.redd.itjoinsFIREFOX_FIRST_HOSTS. The identity is chosen once per redirect chain, and the reddit.com feed hop answered chrome with a 403 in my runs, so a short link that starts with chrome costs two more requests against reddit's rate limit before the firefox retry gets it.Test.
tests/fetch.test.jsgains one test with a fake impers: a redd.it link that 301s to/comments/abc123is fetched as/comments/abc123/.rss, and with a reddit.com cookie jar the hop is left as the page. Onmainit fails withaskedending inhttps://www.reddit.com/comments/abc123.identityOrdergains aredd.itassertion. Full suite on Windows (Node 24): 316 tests, 313 pass, 3 skipped, 0 fail.Left alone. A redirect from a feed back to an HTML page would now be rewritten to the feed again and stop at the 20-hop limit rather than landing on the wall; reddit does not do that today, and either way the page is unreadable. No CHANGELOG line, to keep this round's PRs from conflicting there.
🤖 Generated with Claude Code