From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: url-cache - (require 'url) Date: Mon, 16 Jan 2006 13:45:28 -0500 Message-ID: References: <87y81zusp7.fsf-monnier+emacs@gnu.org> <87hd8mvc6k.fsf-monnier+emacs@gnu.org> <87ek3qt77f.fsf-monnier+emacs@gnu.org> <21C6AB91-2B23-417B-A0BE-AFD7EA2DA05D@gmail.com> <87irsynxvz.fsf-monnier+emacs@gnu.org> <871wzlp6o1.fsf@stone.tss.usg.edu> <878xtqmbb6.fsf-monnier+emacs@gnu.org> <871wzaoe23.fsf@stone.tss.usg.edu> <87u0c6rtgo.fsf-monnier+emacs@gnu.org> <87bqyexf0q.fsf@stone.tss.usg.edu> <87oe2erpo4.fsf-monnier+emacs@gnu.org> <873bjpxsmd.fsf@stone.tss.usg.edu> <874q44x4y1.fsf@stone.tss.usg.edu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1137441689 27901 80.91.229.2 (16 Jan 2006 20:01:29 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 16 Jan 2006 20:01:29 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 16 21:01:19 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EyaXV-0001gD-AP for ged-emacs-devel@m.gmane.org; Mon, 16 Jan 2006 21:01:17 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EyaZn-0002NM-Mn for ged-emacs-devel@m.gmane.org; Mon, 16 Jan 2006 15:03:39 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EyZOZ-0004lx-Jg for emacs-devel@gnu.org; Mon, 16 Jan 2006 13:48:00 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EyZOX-0004kJ-4e for emacs-devel@gnu.org; Mon, 16 Jan 2006 13:47:58 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EyZOW-0004jx-R8 for emacs-devel@gnu.org; Mon, 16 Jan 2006 13:47:56 -0500 Original-Received: from [132.204.24.67] (helo=mercure.iro.umontreal.ca) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EyZS4-0001cv-7i for emacs-devel@gnu.org; Mon, 16 Jan 2006 13:51:36 -0500 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id 36B3033E616; Mon, 16 Jan 2006 13:45:32 -0500 (EST) Original-Received: from asado.iro.umontreal.ca (asado.iro.umontreal.ca [132.204.24.84]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id C645B4AC00A; Mon, 16 Jan 2006 13:45:28 -0500 (EST) Original-Received: by asado.iro.umontreal.ca (Postfix, from userid 20848) id A9F7FE6C1F; Mon, 16 Jan 2006 13:45:28 -0500 (EST) Original-To: Mark Plaksin In-Reply-To: <874q44x4y1.fsf@stone.tss.usg.edu> (Mark Plaksin's message of "Sun, 15 Jan 2006 21:49:26 -0500") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-4.854, requis 5, autolearn=not spam, AWL 0.05, BAYES_00 -4.90) X-MailScanner-From: monnier@iro.umontreal.ca X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:49183 Archived-At: >>> Maybe there's a better approach to the problem I'm trying to solve. I want >>> to add support for ETags to nnrss in Gnus. To do that, nnrss needs access >>> to HTTP headers. nnrss currently uses mm-url-insert which calls >>> url-insert-file-contents. Those seem like the right functions to use but >>> they don't provide access to the HTTP headers. >> >> Why do they seem better to you than url-retrieve (or even url-http) given >> the fact that they do not give you the info you need? > Because url-insert-file-contents does some coding-system things that I > assume are important for inserting URLs into buffers. I don't know > anything about coding-systems. I could write a new function that uses > url-retrieve or url-http but I'd probably have to duplicate the > coding-system parts which seems wasteful. > It also seems that other applications that want to insert the contents of a > URL could benefit from having access to HTTP headers. Good point. I guess a good answer to that is simply to make url-insert-file-contents "trivial" by moving most of its contents to a separate function. Say url-insert, as in the patch below. Does that provide the functionality you're looking for? Stefan --- url-handlers.el 03 jan 2006 11:16:30 -0500 1.16 +++ url-handlers.el 16 jan 2006 13:42:03 -0500 @@ -197,33 +197,47 @@ (url-copy-file url filename) filename)) +(defun url-insert (buffer &optional beg end) + "Insert the body of a URL object. +BUFFER should be a complete URL buffer as returned by `url-retrieve'. +If the headers specify a coding-system, it is applied to the body before it is inserted. +Returns a list of the form (SIZE CHARSET), where SIZE is the size in bytes +of the inserted text and CHARSET is the charset that was specified in the header, +or nil if none was found. +BEG and END can be used to only insert a subpart of the body. +They count bytes from the beginning of the body." + (let* ((handle (with-current-buffer buffer (mm-dissect-buffer t))) + (data (with-current-buffer (mm-handle-buffer handle) + (if beg + (buffer-substring (+ (point-min) beg) + (if end (+ (point-min) end) (point-max))) + (buffer-string)))) + (charset (mail-content-type-get (mm-handle-type handle) + 'charset))) + (mm-destroy-parts handle) + (if charset + (insert (mm-decode-string data (mm-charset-to-coding-system charset))) + (insert data)) + (list (length data) charset))) + ;;;###autoload (defun url-insert-file-contents (url &optional visit beg end replace) - (let ((buffer (url-retrieve-synchronously url)) - (handle nil) - (charset nil) - (data nil)) + (let ((buffer (url-retrieve-synchronously url))) (if (not buffer) (error "Opening input file: No such file or directory, %s" url)) (if visit (setq buffer-file-name url)) - (with-current-buffer buffer - (setq handle (mm-dissect-buffer t)) - (set-buffer (mm-handle-buffer handle)) - (setq data (if beg (buffer-substring beg end) - (buffer-string)))) - (kill-buffer buffer) - (mm-destroy-parts handle) - (if replace (delete-region (point-min) (point-max))) (save-excursion - (setq charset (mail-content-type-get (mm-handle-type handle) - 'charset)) - (let ((start (point))) - (if charset - (insert (mm-decode-string data (mm-charset-to-coding-system charset))) - (progn - (insert data) - (decode-coding-inserted-region start (point) url visit beg end replace))))) - (list url (length data)))) + (let* ((start (point)) + (size-and-charset (url-insert buffer beg end))) + (kill-buffer buffer) + (when replace + (delete-region (point-min) start) + (delete-region (point) (point-max))) + (unless (cadr size-and-charset) + ;; If the headers don't specify any particular charset, use the + ;; usual heuristic/rules that we apply to files. + (decode-coding-inserted-region start (point) url visit beg end replace)) + (list url (car size-and-charset)))))) (defun url-file-name-completion (url directory) (error "Unimplemented"))