Skip to content

Add cache headers to document URLs endpoint#3766

Merged
martincostello merged 4 commits intomasterfrom
copilot/update-cache-headers-for-endpoints
Feb 1, 2026
Merged

Add cache headers to document URLs endpoint#3766
martincostello merged 4 commits intomasterfrom
copilot/update-cache-headers-for-endpoints

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

The issue or feature being addressed

The document URLs endpoint (/swagger/documentUrls) lacks cache control headers, causing browsers to cache stale data indefinitely.

Details on the issue fix or feature implementation

Updated RespondWithDocumentUrls to compute SHA1-based ETag and apply cache headers via existing SetHeaders method, matching the pattern in RespondWithFile:

var etag = HashText(json);
SetHeaders(response, _options, etag);

Extracted HashText as a shared static method to eliminate duplication between RespondWithFile and RespondWithDocumentUrls.

Added integration test DocumentUrlsEndpoint_ReturnsJsonWithCacheHeaders verifying ETag (weak) and Cache-Control headers (Private, MaxAge=7d or no-cache/no-store based on CacheLifetime config).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • scarf.sh
    • Triggering command: /usr/local/bin/node node ./report.js (dns block)
    • Triggering command: /usr/local/bin/node node ./report.js artifacts/bin/Cl--noprofile (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature request]: Cache-bust endpoint URLs resource</issue_title>
<issue_description>### Is your feature request related to a specific problem? Or an existing feature?

Context: #3709 (comment)

The document URLs endpoint can get cached in browsers and go out-of-date.

Describe the solution you'd like

We should update the method below to respond with cache headers like we do for files:

private async Task RespondWithDocumentUrls(HttpResponse response)

Additional context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 1, 2026 08:20
Co-authored-by: martincostello <1439341+martincostello@users.noreply.github.com>
Co-authored-by: martincostello <1439341+martincostello@users.noreply.github.com>
Copilot AI changed the title [WIP] Update cache headers for document URLs endpoint Add cache headers to document URLs endpoint Feb 1, 2026
Copilot AI requested a review from martincostello February 1, 2026 08:26
@martincostello martincostello marked this pull request as ready for review February 1, 2026 08:34
Copilot AI review requested due to automatic review settings February 1, 2026 08:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR ensures the Swagger UI document URLs endpoint (/swagger/documentUrls) participates in the same cache-busting behavior as other Swagger UI resources by adding ETag and cache headers. It also refactors ETag computation within SwaggerUIMiddleware to avoid duplication and adds an integration test around the new behavior.

Changes:

  • Updated SwaggerUIMiddleware.RespondWithDocumentUrls to compute a SHA1-based ETag for the JSON payload and apply cache headers via the existing SetHeaders helper.
  • Refactored the ETag helper from a local static function in RespondWithFile into a shared private static HashText method on SwaggerUIMiddleware.
  • Added an integration test DocumentUrlsEndpoint_ReturnsJsonWithCacheHeaders to verify that /swagger/documentUrls returns the expected content type, body contents, weak ETag, and Cache-Control headers (private with 7-day max-age under default configuration).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs Reuses a shared HashText helper and updates RespondWithDocumentUrls to emit weak ETags and cache headers consistent with other Swagger UI responses.
test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs Adds an integration test for /swagger/documentUrls to assert content, weak ETag presence, and Cache-Control configuration under the default MultipleVersions test site setup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Feb 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.90%. Comparing base (1bbe001) to head (796008d).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3766      +/-   ##
==========================================
+ Coverage   94.67%   94.90%   +0.23%     
==========================================
  Files         111      111              
  Lines        3868     3870       +2     
  Branches      780      780              
==========================================
+ Hits         3662     3673      +11     
+ Misses        206      197       -9     
Flag Coverage Δ
Linux 94.90% <100.00%> (+0.23%) ⬆️
Windows 94.90% <100.00%> (+0.23%) ⬆️
macOS 94.90% <100.00%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This was referenced Feb 6, 2026
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.

[Feature request]: Cache-bust endpoint URLs resource

2 participants