Skip to content

fix(prerender): keep the headers of the http error the fetch got - #317

Merged
Kikobeats merged 2 commits into
masterfrom
Kikobeats/rejected-fetch-headers
Nov 21, 2026
Merged

Kikobeats merged 2 commits into
masterfrom
Kikobeats/rejected-fetch-headers

Conversation

@Kikobeats

@Kikobeats Kikobeats commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

When prerender throws (empty response) and the fetch it ran alongside failed with an HTTP error, the fallback took statusCode from error.response but read headers from a field the reflected failure never carried, so the result had headers: {}.

Seen in production on 2026-11-21: Canva answers our datacenter IPs 403 + cf-mitigated: challenge. The API logged is-antibot:info no challenge detected ... statusCode=403 provider=null, ran no retry, and served the 403 page as status: success with image: null. With the header present, is-antibot detects Cloudflare from headers alone.

The reflected failure now carries the same url, headers and statusCode as the unreflected one, and the fallback reads them from there.

Test: a failed prerender keeps the headers of the http error the fetch got in test/mode.js fails without the change and passes with it. The full suite passes apart from 13 PDF tests that fail the same way on unmodified master on my machine.

🤖 Generated with Claude Code


Note

Medium Risk
Touches core fetch/prerender error paths used in production antibot and fallback behavior, but the change is narrow and well covered by new tests.

Overview
Fixes a gap where parallel reflect fetch failures only surfaced url and statusCode, so when prerender fell back after a failed fetch the result had empty headers and antibot logic (e.g. Cloudflare cf-mitigated) could not run.

Fetch error handling now builds a shared answer (url, headers, statusCode) for both reflected and normal failures. The prerender rejection path uses data.headers and data.statusCode from that payload instead of error.response / defaults.

New tests cover header preservation on failed prerender + HTTP error, successful fetch fallback when browserless throws, connection failures, and stripping error response bodies from fetch HTML.

Reviewed by Cursor Bugbot for commit 348eb36. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Failed prerender requests now retain the original fetch’s HTTP status and response headers, including when prerendering fails.
    • Fetch failure results consistently include the failing URL and available response details. Missing headers are represented as empty headers, and unavailable status is left undefined.
    • Ordinary fetch failures continue to return empty HTML and fetch details. HTTP error response bodies are not exposed in rendered output.
    • Empty prerender results retain prerender mode after a rejected fetch and fall back to fetch mode after a successful fetch.

When prerender throws and the fetch it ran alongside failed with an http
error, the fallback took the status code from the error but read headers
from a field the reflected failure never carried, so every header was
dropped. A Cloudflare challenge then reached the caller as a bare 403:
is-antibot saw statusCode=403 without cf-mitigated and detected nothing,
so no retry ran (canva.link from datacenter IPs, 2026-11-21).

The reflected failure now carries the same url, headers and status code
as the unreflected one, and the fallback reads them from there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Fetch failures now include URL, headers, and status. Rejected-fetch prerender results use headers and status from the fetched data. Tests cover HTTP failures, connection failures, and fallback behavior.

Changes: Fetch Failure Metadata

Layer / File(s) Summary
Propagate fetch metadata and verify result modes
src/index.js, test/mode.js, test/url.js
Fetch failure results include shared URL, headers, and status fields. Rejected-fetch prerender results use headers and status from the fetched data. Tests check HTTP 403 and 500 responses, connection failures, and fetch-mode fallback.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to 348eb

This change keeps response headers and status from failed fetches, so prerender fallbacks no longer hide headers such as Cloudflare's challenge marker. The new tests cover the intended behavior and no merge-blocking issue was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: prerender fallback keeps the headers of the HTTP error that the parallel fetch received. The objectives and summary describe the same fix, which makes headers and stat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: prerender fallback keeps the headers of the HTTP error that the parallel fetch received. The objectives and summary describe the same fix, which makes headers and statusCode flow from the fetch failure payload into the prerender result, and tests cover headers retained on a 403 with cf-mitigated. The title is specific and matches the changeset, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3a7bf27c-3702-4761-bc32-e2e16adcce26
Commits

Reviewing files that changed from the base of the PR and between a498f76 and 348eb36.

Files selected for processing: 2

  • test/mode.js
  • test/url.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

html-get

Details
Benchmark suite Current: 348eb36 Previous: c356aed Ratio
html rewriteUrls off 119.5 ms (114-124.7) 119.8 ms (114.2-124.8) 1.00
html rewriteUrls on 168.8 ms (167-179.8) 166.4 ms (159.4-166.6) 1.01
pdf extract 89.4 ms (88.8-91.2) 88.8 ms (88.3-90.7) 1.01
cold require 201.3 ms (199.6-202.5) 202 ms (200.9-202.8) 1.00

This comment was automatically generated by workflow using github-action-benchmark.

A connection failure must keep an empty headers object, an HTTP error must drop its body, and a prerender throw must return a successful fetch instead of an empty page.
@Kikobeats
Kikobeats merged commit 7750204 into master Nov 21, 2026
5 checks passed
@Kikobeats
Kikobeats deleted the Kikobeats/rejected-fetch-headers branch November 21, 2026 09:58
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.

1 participant