[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/with-url f402e35 3/8: Heed the Cache-Control heade
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] scratch/with-url f402e35 3/8: Heed the Cache-Control header |
Date: |
Sun, 22 Jan 2017 22:25:22 +0000 (UTC) |
branch: scratch/with-url
commit f402e351cc2810709a838b479949de94f810af0e
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
Heed the Cache-Control header
---
lisp/url/with-url.el | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/lisp/url/with-url.el b/lisp/url/with-url.el
index a38f0f3..b696870 100644
--- a/lisp/url/with-url.el
+++ b/lisp/url/with-url.el
@@ -701,7 +701,10 @@ If the headers don't allow caching, nothing will be done."
;; future.
(let ((expires nil))
(current-buffer)
- (when (and (url-header 'last-modified)
+ (when (and (or (url-header 'last-modified)
+ (and (url-header 'cache-control)
+ (setq expires (with-url--parse-cache-control
+ (url-header 'cache-control)))))
(or (not (url-header 'expires))
(progn
(setq expires
@@ -717,7 +720,8 @@ If the headers don't allow caching, nothing will be done."
(insert "Content-Type: " (or (url-header 'content-type buffer)
"text/plain")
"\n")
- (insert "Last-Modified: " (url-header 'last-modified buffer) "\n")
+ (when (url-header 'last-modified buffer)
+ (insert "Last-Modified: " (url-header 'last-modified buffer) "\n"))
;; If there's no Expires header, we cache for one day.
(insert "Expires: "
(let ((system-time-locale "C"))
@@ -733,6 +737,12 @@ If the headers don't allow caching, nothing will be done."
(make-directory (file-name-directory file) t))
(write-region (point-min) (point-max) file nil 'silent)))))))
+(defun with-url--parse-cache-control (control)
+ ;; Cache-Control: public, max-age=604800
+ (when (string-match "max-age *= *\\([0-9]+\\)" control)
+ (time-add (current-time) (seconds-to-time
+ (string-to-number (match-string 1 control))))))
+
(defun with-url-cache-time (url)
"Return the Last-Modified timestamp for the cached version of URL, if any."
(let ((file (with-url--cache-file-name url)))
- [Emacs-diffs] scratch/with-url updated (3322f8f -> 03b56ca), Lars Ingebrigtsen, 2017/01/22
- [Emacs-diffs] scratch/with-url f402e35 3/8: Heed the Cache-Control header,
Lars Ingebrigtsen <=
- [Emacs-diffs] scratch/with-url 3733456 2/8: Adapt to the new cache, Lars Ingebrigtsen, 2017/01/22
- [Emacs-diffs] scratch/with-url 1c59f8a 6/8: Get chunked decoding right, Lars Ingebrigtsen, 2017/01/22
- [Emacs-diffs] scratch/with-url 4fb09fd 4/8: Build fix, Lars Ingebrigtsen, 2017/01/22
- [Emacs-diffs] scratch/with-url bc505fd 1/8: Fix up some :wait issues, Lars Ingebrigtsen, 2017/01/22
- [Emacs-diffs] scratch/with-url b6d6172 7/8: Don't move point around when inserting images, Lars Ingebrigtsen, 2017/01/22
- [Emacs-diffs] scratch/with-url 2415aae 5/8: Make reloading work again., Lars Ingebrigtsen, 2017/01/22
- [Emacs-diffs] scratch/with-url 03b56ca 8/8: Respect the buffer parameter, Lars Ingebrigtsen, 2017/01/22