Skip to content

Conversation

@YoshihitoAso
Copy link
Member

@YoshihitoAso YoshihitoAso commented Jan 14, 2026

📌 Description

This pull request introduces a new middleware to manage HTTP caching headers based on response status codes, improving cache control and compliance with RFC9111/RFC7231.

✅ Related Issues

None

🔄 Changes

Middleware Addition and Integration

  • Added CacheControlMiddleware to the codebase, which enforces cache header policies by status code, allowing cache only for specific whitelisted statuses (e.g., 200, 301, 404) and disabling cache for others. (app/middleware/cache_control.py)
  • Registered CacheControlMiddleware in the middleware initialization and main application setup, ensuring it is applied to all incoming requests. (app/middleware/__init__.py, app/main.py) [1] [2] [3]

📌 Checklist

  • I have added tests where necessary.
  • I have updated the documentation where necessary.

@github-actions
Copy link

github-actions bot commented Jan 14, 2026

Coverage

Coverage Report •
FileStmtsMissCoverMissing
app
   main.py1411986%107–108, 112, 117–119, 148–149, 192, 202–204, 213–214, 217, 221, 226, 230, 352
app/middleware
   __init__.py30100% 
   cache_control.py27581%76, 84, 86–87, 89
TOTAL46445159596% 

Tests Skipped Failures Errors Time
1538 0 💤 0 ❌ 0 🔥 12m 22s ⏱️

"""
Middleware to control caching headers.
- For 4xx and 5xx responses: enforce no-store/no-cache headers and remove validators.
- For other responses: mirror incoming request's Cache-Control/Pragma/ETag/Expires if present.
Copy link
Member

Choose a reason for hiding this comment

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

[qa]
If possible, I’d like to understand the intent behind mirroring request headers (Cache-Control/Pragma/ETag/Expires) into the response for non-error cases, especially for ETag/Expires.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry. There is no need for mirroring other than Cache-Control. I have deleted it.

@YoshihitoAso YoshihitoAso merged commit 8b838e2 into dev-26.3 Jan 15, 2026
11 checks passed
@YoshihitoAso YoshihitoAso deleted the cache-control-middleware branch January 15, 2026 00:34
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.

2 participants