Skip to content

Commit 535f77a

Browse files
committed
Add HTTP caching feature (RFC 7234)
Implement a new :caching feature that stores and reuses HTTP responses according to RFC 7234 freshness and validation semantics. Only GET and HEAD responses are cached. Supports Cache-Control (max-age, no-cache, no-store), Expires, ETag / If-None-Match, and Last-Modified / If-Modified-Since for freshness checks and conditional revalidation. Ships with a default in-memory store. Custom stores can be passed via the store option. Closes #223.
1 parent 2a1e5b3 commit 535f77a

8 files changed

Lines changed: 1485 additions & 0 deletions

File tree

.mutant.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ matcher:
2525
- HTTP::URI*
2626
- HTTP::Headers*
2727
- HTTP::Redirector*
28+
- HTTP::Features::Caching*
2829
- HTTP::Features::RaiseError*
2930
- HTTP::Base64*
3031
ignore:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3737

3838
### Added
3939

40+
- HTTP caching feature (`HTTP.use(:caching)`) that stores and reuses responses
41+
according to RFC 7234. Supports `Cache-Control` (`max-age`, `no-cache`,
42+
`no-store`), `Expires`, `ETag` / `If-None-Match`, and
43+
`Last-Modified` / `If-Modified-Since` for freshness checks and conditional
44+
revalidation. Ships with a default in-memory store; custom stores can be
45+
passed via `store:` option. Only GET and HEAD responses are cached. ([#223])
4046
- `HTTP.base_uri` for setting a base URI that resolves relative request paths
4147
per RFC 3986. Supports chaining (`HTTP.base_uri("https://api.example.com/v1")
4248
.get("users")`), and integrates with `persistent` connections by deriving the

Steepfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ target :lib do
1212
library "singleton"
1313
library "socket"
1414
library "tempfile"
15+
library "time"
1516
library "timeout"
1617
library "uri"
1718
library "zlib"

lib/http/feature.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def on_error(_request, _error); end
7878

7979
require "http/features/auto_inflate"
8080
require "http/features/auto_deflate"
81+
require "http/features/caching"
8182
require "http/features/instrumentation"
8283
require "http/features/logging"
8384
require "http/features/normalize_uri"

0 commit comments

Comments
 (0)