Commit cf058fe
committed
feat: Respect Cache-Control: max-age header
This change implements support for the `Cache-Control: max-age`
HTTP header to avoid fetching feeds that have not expired.
The `Feed` class now stores `last_checked` and `max_age`
attributes. Before fetching a feed, the application checks if the
cached version is still valid based on these attributes. If the
cache is still fresh, the network request is skipped.
After a successful fetch, the `Cache-Control` header is parsed
from the response, and the `last_checked` and `max_age`
attributes are updated. This ensures that subsequent fetches will
respect the cache duration specified by the feed provider.
This commit adds a test case to verify that the `Cache-Control:
max-age` header is respected.
The test starts a webserver that serves a feed with a `max-age`
value, runs the feed to populate the cache, and then checks that
the feed is not fetched again before the `max-age` expires, and
is fetched again after it expires.
Fixes: rss2email#2861 parent 63d657c commit cf058fe
2 files changed
+73
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
| 175 | + | |
174 | 176 | | |
175 | 177 | | |
176 | 178 | | |
| |||
352 | 354 | | |
353 | 355 | | |
354 | 356 | | |
| 357 | + | |
| 358 | + | |
355 | 359 | | |
356 | 360 | | |
357 | 361 | | |
| |||
369 | 373 | | |
370 | 374 | | |
371 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
372 | 383 | | |
373 | 384 | | |
374 | 385 | | |
| |||
937 | 948 | | |
938 | 949 | | |
939 | 950 | | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
940 | 962 | | |
941 | 963 | | |
942 | 964 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
252 | 270 | | |
253 | 271 | | |
254 | 272 | | |
| |||
379 | 397 | | |
380 | 398 | | |
381 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
382 | 433 | | |
383 | 434 | | |
384 | 435 | | |
| |||
0 commit comments