[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

Re: 304 check (was: Form reuse doesn't update content)



My earlier patch on the parent thread seems to work well so far, but I
noticed a comment in the code (w3m.el ~line 1705):

  ;; FIXME: we need to check whether contents were updated in remote servers.
  (defun w3m-cache-available-p (url)

A little wikipedia research lead me to:

  https://en.wikipedia.org/wiki/HTTP_ETag

Which lead me to try the attached patch.

However, either I've made an error in constructing the 'If-None-Match:'
header, or I haven't found a website that actually uses the
non-mandatory 304 response.

At this point, I would appreciate some help from someone on the list to figure
out a way to get reliably get 304 responses for testing. Maybe it's
something I mis-coded, or maybe I just haven't performed the correct
user navigation procedure, or maybe I've chosen non-compliant websites (ie.
wikipedia, emacswiki).

I've also failed to generate a 304 response using the python3 module:

  python3 -m http.server --bind 127.0.0.4

My test page loads, but always with a 200 response.

Any ideas?

-- 
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1706
diff -u -r1.1706 w3m.el
--- w3m.el	27 Feb 2018 06:23:35 -0000	1.1706
+++ w3m.el	3 Apr 2018 20:26:28 -0000
@@ -4913,20 +5030,26 @@
 	      (setq end (next-single-property-change
 			 (1+ beg) 'w3m-cache (current-buffer) (point-max)))
 	    ;; It wasn't in the cache after all.
-	    (setq w3m-cache-articles (delq ident w3m-cache-articles))))
+	    (setq w3m-cache-articles (delq ident w3m-cache-articles)))
+         ; (unless (and (goto-char beg)
+         ;              (search-forward "<textarea"end t))
+         ;   (setq beg nil)))
+        );
 	(and beg
 	     end
 	     (with-current-buffer (or buffer (current-buffer))
 	       (let ((inhibit-read-only t))
 		 (insert-buffer-substring w3m-cache-buffer beg end))
-	       t))))))
+ 	       t))))))
+

 ;; FIXME: we need to check whether contents were updated in remote servers.
 (defun w3m-cache-available-p (url)
   "Return non-nil if a content of URL has already been cached."
   (w3m-cache-setup)
   (when (stringp url)
-    (let ((ident (intern (w3m-w3m-canonicalize-url url) w3m-cache-hashtb)))
+    (let ((ident (intern (w3m-w3m-canonicalize-url url) w3m-cache-hashtb))
+          etag)
       (and
        (memq ident w3m-cache-articles)
        (or
@@ -4935,6 +5058,7 @@
 	  (let ((case-fold-search t)
 		(head (and (boundp ident) (symbol-value ident)))
 		time expire)
+(message "Boruch: head=%s" head)
 	    (cond
 	     ((and (string-match "^\\(?:date\\|etag\\):[ \t]" head)
 		   (or (string-match "^pragma:[ \t]+no-cache\n" head)
@@ -4962,12 +5086,14 @@
 	       (setq expire (match-string 1 head))
 	       (setq expire (w3m-time-parse-string expire)))
 	      (w3m-time-newer-p expire (current-time)))
+             ((string-match "^etag:[ \t]\\([^\n]+\\)\n" head)
+               (setq etag (concat "If-None-Match: " (match-string 1 head))))
 	     (t
 	      ;; Adhoc heuristic rule: pages with neither
 	      ;; Last-Modified header and ETag header are treated as
 	      ;; dynamically-generated pages.
 	      (string-match "^\\(?:last-modified\\|etag\\):" head))))))
-       ident))))
+       (cons ident etag)))))

 (defun w3m-read-file-name (&optional prompt dir default existing)
   (unless prompt
@@ -5682,6 +5808,7 @@
 		(w3m-w3m-retrieve-1 url post-data referer no-cache
 				    (or w3m-follow-redirection 0) handler)))
       (setq w3m-http-status (car-safe attr))
+(message "Boruch: w3m-http-status = %s" w3m-http-status)
       (let ((w3m-message-silent silent))
 	(when attr
 	  (cond
@@ -5703,18 +5830,22 @@

 (defun w3m-w3m-retrieve-1 (url post-data referer no-cache counter handler)
   "A subroutine for `w3m-w3m-retrieve'."
-  (let ((w3m-command-arguments
+  (let* ((w3m-command-arguments
 	 (append w3m-command-arguments
 		 (when (member "cookie" w3m-compile-options)
 		   (list "-no-cookie"))
 		 (list "-o" "follow_redirection=0")
 		 (w3m-additional-command-arguments url)))
 	(cachep (w3m-cache-available-p url))
+        (etag (cdr cachep))
 	temp-file)
     (when (and w3m-broken-proxy-cache
 	       (or no-cache (not cachep)))
-      (setq w3m-command-arguments
+       (setq w3m-command-arguments
 	    (append w3m-command-arguments '("-o" "no_cache=1"))))
+    (when etag
+      (setq w3m-command-arguments
+        (append w3m-command-arguments (list "-header" etag))))
     (setq temp-file
 	  (when (or (eq w3m-type 'w3mmee) post-data)
 	    (make-temp-name
@@ -5732,6 +5863,10 @@
 				 post-data)
 			       referer
 			       (if (consp post-data) (car post-data))))))
+(message "Boruch w3m-command-args=%s" w3m-command-arguments)
+(message "Boruch cachep=%s" cachep)
+
+
     (lexical-let ((url url)
 		  (post-data post-data)
 		  (referer referer)
@@ -6487,8 +6622,8 @@
 			  w3m-current-title "Fail"))))
 	      (w3m-arrived-add url nil (current-time) (current-time))
 	      (ding)
-	      (when (eq (car w3m-current-forms) t)
-		(setq w3m-current-forms (cdr w3m-current-forms)))
+;	      (when (eq (car w3m-current-forms) t)
+;		(setq w3m-current-forms (cdr w3m-current-forms)))
 	      (prog1 (when (and w3m-show-error-information
 				(not (or (w3m-url-local-p url)
 					 (string-match "\\`about:" url))))