Skip to content

Commit ccf3ad8

Browse files
committed
Fix cache headers on early forced redirect responses
When forced redirects fire before URL resolution (the new early check), set request.path_project_slug and attempt to resolve the path to get version info for proper CDN cache control and cache tag headers. If resolution fails (e.g., "/" before system redirect), default to caching the redirect response since the target URL will handle authz.
1 parent 8a7101c commit ccf3ad8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

readthedocs/proxito/views/serve.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@ def serve_path(self, request, path):
196196
forced_only=True,
197197
)
198198
if redirect_response:
199+
# Set request attributes for the middleware to use
200+
# (cache tags, CDN headers, etc).
201+
# Since we haven't resolved the path yet, we try to resolve
202+
# it now to get the version info for proper cache headers.
203+
request.path_project_slug = unresolved_domain.project.slug
204+
try:
205+
unresolved = unresolver.unresolve_path(
206+
unresolved_domain=unresolved_domain,
207+
path=path,
208+
append_indexhtml=False,
209+
)
210+
request.path_version_slug = unresolved.version.slug
211+
self.cache_response = unresolved.version.is_public
212+
except Exception:
213+
# If the path can't be resolved (e.g., "/" before
214+
# system redirect), we still return the redirect
215+
# but let the middleware set default cache headers.
216+
self.cache_response = True
199217
return redirect_response
200218
except InfiniteRedirectException:
201219
pass

0 commit comments

Comments
 (0)