--- url-http.el.orig 2006-01-14 13:11:31.000000000 -0500 +++ url-http.el 2006-01-14 13:30:37.000000000 -0500 @@ -67,6 +67,15 @@ request. ") +(defvar url-http-save-headers nil + "If t save HTTP headers in url-http-headers. +Defaults to nil. Useful toggle switch for applications that need access +to HTTP headers.") + +(defvar url-http-headers nil + "Alist of HTTP headers +Populated when a URL is retrieved and url-http-save-headers is set to t.") + ;(eval-when-compile ;; These are all macros so that they are hidden from external sight ;; when the file is byte-compiled. @@ -382,6 +391,8 @@ (url-http-parse-response) (mail-narrow-to-head) ;;(narrow-to-region (point-min) url-http-end-of-headers) + (if url-http-save-headers + (setq url-http-headers (url-http-get-all-headers))) (let ((class nil) (success nil)) (setq class (/ url-http-response-status 100)) @@ -1229,6 +1240,32 @@ (if buffer (kill-buffer buffer)) options)) +(defun url-http-get-all-headers () + "Return an alist of HTTP headers. +Assumes it is called from a buffer which has been narrowed to the headers." + (save-excursion + (let (opoint header value alist) + (point-min) + ;; Skip the HTTP status + (forward-line 1) + (while (not (= (point) (point-max))) + (setq opoint (point)) + (re-search-forward ":") + (forward-char -1) + (setq header (buffer-substring-no-properties opoint (point))) + (re-search-forward ":[\t ]*") + (setq opoint (point)) + ;; find the end of the header + (while (progn (forward-line 1) + (looking-at "[ \t]"))) + ;; Back up over newline, then trailing spaces or tabs + (forward-char -1) + (skip-chars-backward " \t" opoint) + (setq value (buffer-substring-no-properties opoint (point))) + (forward-line 1) + (add-to-list 'alist `(,header . ,value))) + alist))) + (provide 'url-http) ;; arch-tag: ba7c59ae-c0f4-4a31-9617-d85f221732ee