mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-26 15:21:51 -08:00
* lisp/url/url-dav.el: Use lexical-binding. (url-dav-process-DAV:prop): Remove unused var `handler-func`. (url-dav-lock-resource): Remove unused var `child-url`. (url-dav-active-locks): Remove unused var `properties`. (url-dav-delete-directory): Remove unused var `props`. (url-dav-file-name-completion): Remove unused var `result`. * lisp/url/url-expand.el (url-expand-file-name): Use \s * lisp/url/url-file.el (url-file): Improve regexp. * lisp/url/url-gw.el: Use lexical-binding. (url-open-stream): Remove unused var `cur-retries`, `retry`, `errobj`. * lisp/url/url-imap.el: Use lexical-binding. (imap-username, imap-password): Declare. * lisp/url/url-mailto.el: Use lexical-binding. (url-mailto): Remove unused var `func`. Use `push`. * lisp/url/url-news.el: Use lexical-binding. (url-news): Remove unused var `article-brackets`. * lisp/url/url-cid.el: * lisp/url/url-cache.el: * lisp/url/url-about.el: * lisp/url/url-tramp.el: * lisp/url/url-proxy.el: * lisp/url/url-privacy.el: * lisp/url/url-nfs.el: * lisp/url/url-ldap.el: * lisp/url/url-misc.el: * lisp/url/url-methods.el: Use lexical-binding.
80 lines
2.5 KiB
EmacsLisp
80 lines
2.5 KiB
EmacsLisp
;;; url-proxy.el --- Proxy server support -*- lexical-binding: t; -*-
|
|
|
|
;; Copyright (C) 1999, 2004-2021 Free Software Foundation, Inc.
|
|
|
|
;; Keywords: comm, data, processes, hypermedia
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Code:
|
|
|
|
(require 'url-parse)
|
|
|
|
(defun url-default-find-proxy-for-url (urlobj host)
|
|
(cond
|
|
((or (and (assoc "no_proxy" url-proxy-services)
|
|
(string-match
|
|
(cdr
|
|
(assoc "no_proxy" url-proxy-services))
|
|
host))
|
|
(equal "www" (url-type urlobj)))
|
|
"DIRECT")
|
|
((cdr (assoc (url-type urlobj) url-proxy-services))
|
|
(concat "PROXY " (cdr (assoc (url-type urlobj) url-proxy-services))))
|
|
;;
|
|
;; Should check for socks
|
|
;;
|
|
(t
|
|
"DIRECT")))
|
|
|
|
(defvar url-proxy-locator 'url-default-find-proxy-for-url)
|
|
|
|
(defun url-find-proxy-for-url (url host)
|
|
(let ((proxies (split-string (funcall url-proxy-locator url host) " *; *"))
|
|
(proxy nil)
|
|
(case-fold-search t))
|
|
;; Not sure how I should handle gracefully degrading from one proxy to
|
|
;; another, so for now just deal with the first one
|
|
;; (while proxies
|
|
(if (listp proxies)
|
|
(setq proxy (car proxies))
|
|
(setq proxy proxies))
|
|
(cond
|
|
((string-match "^direct" proxy) nil)
|
|
((string-match "^proxy +" proxy)
|
|
(concat "http://" (substring proxy (match-end 0)) "/"))
|
|
((string-match "^socks +" proxy)
|
|
(concat "socks://" (substring proxy (match-end 0))))
|
|
(t
|
|
(display-warning 'url (format "Unknown proxy directive: %s" proxy) :error)
|
|
nil))))
|
|
|
|
(autoload 'url-http "url-http")
|
|
|
|
(defun url-proxy (url callback &optional cbargs)
|
|
;; Retrieve URL from a proxy.
|
|
;; Expects `url-using-proxy' to be bound to the specific proxy to use."
|
|
(setq url-using-proxy (url-generic-parse-url url-using-proxy))
|
|
|
|
(cond
|
|
((string= (url-type url-using-proxy) "http")
|
|
(url-http url callback cbargs))
|
|
(t
|
|
(error "Don't know how to use proxy `%s'" url-using-proxy))))
|
|
|
|
(provide 'url-proxy)
|
|
|
|
;;; url-proxy.el ends here
|