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