Repository navigation
fix(fetch): report the url that answered an http error - #316
Conversation
When a redirect chain ends on a 4xx/5xx, got rejects and the fetch branch reported the requested url instead of the one that answered. The redirects were right and the prerender branch already used response.url(), so the two modes disagreed on the same chain: /blocked -> 302 -> /denied (403) came back as url /blocked in fetch mode and /denied in prerender mode. microlink-api needs the real final url of an origin probe that ended on an antibot wall to tell whether a proxied hop landed on the same page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
html-get
Details
| Benchmark suite | Current: ca9c397 | Previous: 15f2dc6 | Ratio |
|---|---|---|---|
html rewriteUrls off |
138.8 ms (137.3-141.7) |
141.9 ms (136.2-151.2) |
0.98 |
html rewriteUrls on |
212.4 ms (204-220.6) |
212 ms (209.4-217.1) |
1.00 |
pdf extract |
99.5 ms (96-104) |
97.5 ms (96-99.7) |
1.02 |
cold require |
244.8 ms (242.8-247.2) |
243.7 ms (241.9-245.5) |
1.00 |
This comment was automatically generated by workflow using github-action-benchmark.
A browser failure kept the request url while statusCode came from the page that answered the redirect.
Comparing the two modes stayed green when that fallback changed, because both modes now share it.
What
In fetch mode, a redirect chain that ends on a 4xx/5xx reported the requested url instead of the url that answered. Prerender mode already reported
response.url(), so both modes now agree.Why
microlink-api (issue microlink/api#19) returns
redirects: []forhttps://dub.sh/twitter-redirectbecause the winning hop goes through scrape.do, which follows redirects itself. The API takes the redirect chain from its origin probe, but only when the probe ended at the same url as the proxied hop. That probe ends on x.com's antibot wall (an http error), where html-get reported the shortener url, so the check can never match.Tests
test/url.js:{fetch,prerender} » a redirect to an error page reports the url that answered. It failed in fetch mode before the fix and passes in both modes after.test/url.js,test/redirects.js,test/mode.js: 26 passed.test/pdf/**: 12 snapshot failures locally, the same 12 onorigin/master(local mutool output), so they are unrelated.🤖 Generated with Claude Code
Note
Low Risk
Behavior change is limited to error/redirect edge cases in returned metadata; successful fetches are unchanged, but callers that relied on the old (incorrect) URL on errors may see different values.
Overview
Fetch mode now returns the final response URL on HTTP errors (from
error.response.urlwhen present), instead of the originally requested URL. That aligns fetch with prerender’sresponse.url()behavior when a redirect chain ends on a 4xx/5xx.When prerender falls back after a rejected fetch, the error payload uses
data.urlfrom the fetch result rather than the input URL.New tests cover redirect-to-error (fetch + prerender), prerender browser failure, and connection failure still reporting the requested URL when there is no response.
Reviewed by Cursor Bugbot for commit ca9c397. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit