Skip to content

fix(httpx): keep the last response when a redirect target is unreachable - #2707

Merged
Mzack9999 merged 2 commits into
devfrom
fix/2704-follow-redirect-failure
Nov 2, 2026
Merged

Mzack9999 merged 2 commits into
devfrom
fix/2704-follow-redirect-failure

Conversation

@dogancanbakir

@dogancanbakir dogancanbakir commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #2704

With -fr/-fhr, the last reachable response is reported instead of failing the whole request; -debug logs why the redirect stopped. Behavior change: such hosts are now output with their 3xx status.

Summary by CodeRabbit

  • Bug Fixes
    • Redirect handling now preserves the redirect response and its body when the destination cannot be reached, rather than returning only a connection error. This makes the redirect status and response content available in these cases. Requests canceled while following a redirect continue to report cancellation instead of returning the saved redirect response.

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 2e32098e-a48b-4e37-90df-8ebb01345fe5
Commits

Reviewing files that changed from the base of the PR and between 6b89318 and b36dfb3.

Files selected for processing: 2
  • common/httpx/httpx.go
  • common/httpx/httpx_test.go

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

Walkthrough

Redirect handling now saves redirect responses and returns the saved response without an error when the follow-up request fails. A test covers both redirect-following modes with an unreachable target.

Changes

Redirect response recovery

Layer / File(s) Summary
Save and restore redirect responses
common/httpx/httpx.go, common/httpx/httpx_test.go
Both redirect callbacks save the response that initiated the redirect. If the follow-up request fails, getResponse restores its body and returns that response without an error. The test checks both redirect-following modes.

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

Suggested reviewers: mzack9999

Merge Risk: Minimal · up to b36df

No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: retaining the last response when a redirect target is unreachable.
Linked Issues check Passed Issue #2704 requires -fr to retain the last reachable response when a redirect target is unreachable. getResponse restores the saved response and returns it without the redirect error. Both redire…
Out of Scope Changes check Passed The source changes implement redirect-response retention and redirect-stop debug logging. The tests verify the linked redirect behavior. No unrelated change is shown.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #2704 requires -fr to retain the last reachable response when a redirect target is unreachable. getResponse restores the saved response and returns it without the redirect error. Both redirect policies save the response before following the redirect. Tests cover -fr and -fhr, status 301, response body, response chain, and cancellation behavior.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit hops beside the redirect sign,
The last good response stays in the line.
A closed gate blocks the path ahead,
Yet “moved” comes back, its body read.
I nibble clover and call it fine!

@coderabbitai coderabbitai 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.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread common/httpx/httpx.go Resolved
Comment thread common/httpx/httpx.go Resolved
@Mzack9999
Mzack9999 merged commit f878c7a into dev Nov 2, 2026
12 checks passed
@Mzack9999
Mzack9999 deleted the fix/2704-follow-redirect-failure branch November 2, 2026 10:07
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.

-follow-redirects drops the result when a redirect target is unreachable

2 participants