Commit 19f58c7
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 074ca93 commit 19f58c7
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 | |
|---|---|---|---|
| |||
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
241 | 259 | | |
242 | 260 | | |
243 | 261 | | |
| |||
368 | 386 | | |
369 | 387 | | |
370 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
371 | 422 | | |
372 | 423 | | |
373 | 424 | | |
| |||
0 commit comments