unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Mark Plaksin <happy@usg.edu>
Subject: Re: url-cache - (require 'url)
Date: Sat, 14 Jan 2006 13:32:52 -0500	[thread overview]
Message-ID: <871wzaoe23.fsf@stone.tss.usg.edu> (raw)
In-Reply-To: 878xtqmbb6.fsf-monnier+emacs@gnu.org

[-- Attachment #1: Type: text/plain, Size: 886 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> It would also be nice if there was an easy way to get at the HTTP headers
>> associated with a response.  Maybe there is a way but I can't find it.
>
> Maybe for that, url-http is more appropriate.
> After all, there won't be any HTTL headers if the URL is not using HTTP.

Right.  How about this patch to url-http.el?

Test like this:
(setq url-http-save-headers t)
(url-retrieve-synchronously "http://rss.slashdot.org/Slashdot/slashdot")
(setq url-http-save-headers nil)

After that url-http-headers should look like this:
(("Content-Type" . "text/xml;charset=utf-8") ("Transfer-Encoding" . "chunked") ("Connection" . "Keep-Alive") ("Keep-Alive" . "timeout=5, max=100") ("ETag" . "xRkHefoJaorPexoLfvkTcHeudUY") ("Last-Modified" . "Sat, 14 Jan 2006 18:29:23 GMT") ("Server" . "Apache") ("Date" . "Sat, 14 Jan 2006 18:30:49 GMT"))


[-- Attachment #2: url-http.saveheaders.diff --]
[-- Type: text/plain, Size: 2028 bytes --]

--- 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

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  reply	other threads:[~2006-01-14 18:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-01 17:48 url-cache - (require 'url) David Reitter
2006-01-02  5:08 ` Stefan Monnier
2006-01-02  9:47   ` David Reitter
2006-01-02 16:25     ` Stefan Monnier
2006-01-02 18:03       ` David Reitter
2006-01-03  1:46         ` Stefan Monnier
2006-01-03  9:51           ` David Reitter
2006-01-03 15:54             ` Stefan Monnier
2006-01-03 16:15               ` David Reitter
2006-01-03 20:05                 ` Stefan Monnier
2006-01-05 22:11                 ` Stefan Monnier
2006-01-06 18:12                   ` Mark Plaksin
2006-01-09  1:37                     ` Stefan Monnier
2006-01-14 18:32                       ` Mark Plaksin [this message]
2006-01-15  4:45                         ` Stefan Monnier
2006-01-15  4:59                           ` Mark Plaksin
2006-01-15  6:09                             ` Stefan Monnier
2006-01-15 18:18                               ` Mark Plaksin
2006-01-16  2:26                                 ` Stefan Monnier
2006-01-16  2:49                                   ` Mark Plaksin
2006-01-16 18:45                                     ` Stefan Monnier
2006-02-19 19:56                                       ` Mark Plaksin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871wzaoe23.fsf@stone.tss.usg.edu \
    --to=happy@usg.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).