Skip to content

fix(http): skip caching relative 307 redirect locations and resolve them#1777

Merged
gaius-qi merged 1 commit intomainfrom
feature/redirect
Apr 10, 2026
Merged

fix(http): skip caching relative 307 redirect locations and resolve them#1777
gaius-qi merged 1 commit intomainfrom
feature/redirect

Conversation

@gaius-qi
Copy link
Copy Markdown
Member

@gaius-qi gaius-qi commented Apr 10, 2026

Description

This pull request improves how HTTP 307 Temporary Redirects are handled and cached in the dragonfly-client-backend. The main focus is to ensure that only absolute URLs are cached as redirect targets, preventing potential issues with relative URLs. Additionally, a new test verifies this behavior.

Redirect handling and caching improvements:

  • Updated logic in store_temporary_redirect_url to skip caching redirects when the Location header is a relative URL, logging a debug message in such cases. Only absolute URLs are now cached as valid redirect targets.
  • Added a debug log after successfully caching a temporary redirect, making it easier to trace caching behavior.

Redirect resolution and request flow:

  • Changed how redirect URLs are resolved: now, relative Location headers are joined with the base URL to form an absolute URL before following the redirect. However, only the original Location value (not the resolved absolute URL) is considered for caching, aligning with the new caching logic. This change is applied in both the stat and get request flows. [1] [2]

Testing:

  • Added a new async test should_not_cache_relative_307_redirect_location to verify that relative redirect URLs are not cached, ensuring the origin server is contacted again for subsequent requests.

Related Issue

Fixed dragonflyoss/dragonfly#4710

Motivation and Context

Screenshots (if appropriate)

@gaius-qi gaius-qi added this to the v2.5.0 milestone Apr 10, 2026
@gaius-qi gaius-qi self-assigned this Apr 10, 2026
@gaius-qi gaius-qi requested review from a team as code owners April 10, 2026 06:29
@gaius-qi gaius-qi added the enhancement New feature or request label Apr 10, 2026
@github-actions github-actions bot requested a review from hyy0322 April 10, 2026 06:29
@gaius-qi gaius-qi enabled auto-merge (squash) April 10, 2026 06:30
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

❌ Patch coverage is 97.26027% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.66%. Comparing base (5400d49) to head (8c55fa2).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
dragonfly-client-backend/src/http.rs 97.26% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1777      +/-   ##
==========================================
+ Coverage   44.54%   44.66%   +0.12%     
==========================================
  Files          91       91              
  Lines       25834    25905      +71     
==========================================
+ Hits        11508    11571      +63     
- Misses      14326    14334       +8     
Files with missing lines Coverage Δ
dragonfly-client-backend/src/http.rs 97.11% <97.26%> (+0.13%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gaius-qi gaius-qi merged commit 8996b68 into main Apr 10, 2026
9 checks passed
@gaius-qi gaius-qi deleted the feature/redirect branch April 10, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP backend does not handle relative paths in 307 redirect Location header

2 participants