]> code.delx.au - gnu-emacs/blob - lisp/url/url-proxy.el
Merged in changes from CVS HEAD
[gnu-emacs] / lisp / url / url-proxy.el
1 ;;; url-proxy.el --- Proxy server support
2 ;; Keywords: comm, data, processes, hypermedia
3
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 ;;; Copyright (c) 1999 Free Software Foundation, Inc.
6 ;;;
7 ;;; This file is part of GNU Emacs.
8 ;;;
9 ;;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;;; it under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 2, or (at your option)
12 ;;; any later version.
13 ;;;
14 ;;; GNU Emacs is distributed in the hope that it will be useful,
15 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;;; Boston, MA 02111-1307, USA.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24
25 (require 'url-parse)
26 (autoload 'url-warn "url")
27
28 (defun url-default-find-proxy-for-url (urlobj host)
29 (cond
30 ((or (and (assoc "no_proxy" url-proxy-services)
31 (string-match
32 (cdr
33 (assoc "no_proxy" url-proxy-services))
34 host))
35 (equal "www" (url-type urlobj)))
36 "DIRECT")
37 ((cdr (assoc (url-type urlobj) url-proxy-services))
38 (concat "PROXY " (cdr (assoc (url-type urlobj) url-proxy-services))))
39 ;;
40 ;; Should check for socks
41 ;;
42 (t
43 "DIRECT")))
44
45 (defvar url-proxy-locator 'url-default-find-proxy-for-url)
46
47 (defun url-find-proxy-for-url (url host)
48 (let ((proxies (split-string (funcall url-proxy-locator url host) " *; *"))
49 (proxy nil)
50 (case-fold-search t))
51 ;; Not sure how I should handle gracefully degrading from one proxy to
52 ;; another, so for now just deal with the first one
53 ;; (while proxies
54 (if (listp proxies)
55 (setq proxy (car proxies))
56 (setq proxy proxies))
57 (cond
58 ((string-match "^direct" proxy) nil)
59 ((string-match "^proxy +" proxy)
60 (concat "http://" (substring proxy (match-end 0)) "/"))
61 ((string-match "^socks +" proxy)
62 (concat "socks://" (substring proxy (match-end 0))))
63 (t
64 (url-warn 'url (format "Unknown proxy directive: %s" proxy) 'critical)
65 nil))))
66
67 (defun url-proxy (url callback &optional cbargs)
68 ;; Retrieve URL from a proxy.
69 ;; Expects `url-using-proxy' to be bound to the specific proxy to use."
70 (setq url-using-proxy (url-generic-parse-url url-using-proxy))
71 (let ((proxy-object (copy-sequence url)))
72 (url-set-target proxy-object nil)
73 (url-http url-using-proxy callback cbargs)))
74
75 (provide 'url-proxy)
76
77 ;;; arch-tag: 4ff8882e-e498-42b7-abc5-acb449cdbc62