Skip to content

Instantly share code, notes, and snippets.

@cvmat
Last active December 21, 2015 04:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvmat/6250555 to your computer and use it in GitHub Desktop.
Save cvmat/6250555 to your computer and use it in GitHub Desktop.
An advice that enables url.el to connect a server with the HTTPS protocol via a HTTP proxy.
;;
;; If the OpenSSL executable is compiled with the patch in
;; http://rt.openssl.org/Ticket/Display.html?id=2651&user=guest&pass=guest ,
;; the executable can connect a server via a HTTP proxy.
;; With the below code, the url.el library may connect a server with
;; the HTTPS protocol via a HTTP proxy.
;;
;;
;; Register a proxy for the "https" scheme from the environment
;; variable "https_proxy".
;;
(require 'url-methods nil t)
;; You can also specify the environment variable here as
;; (setenv "https_proxy" "http://proxy-host:proxy-port/") .
;; This `setenv' must precede the below call of `url-scheme-register-proxy'.
(url-scheme-register-proxy "https")
;;
;; Configure `tls-program' to use the proxy registered above.
;;
(let* ((proxy (cdr (assoc "https" url-proxy-services))))
(when (and proxy
(string-match "^\\([^:]+\\):\\([0-9]+\\)$" proxy))
(setq tls-program
`(,(concat "openssl s_client -connect %h:%p -no_ssl2 -ign_eof"
" -http_proxy " proxy)
,@tls-program))))
(defadvice url-proxy (around https-proxy activate)
(cond
((string= (url-type url) "https")
(let ((url-using-proxy nil))
(url-https url callback cbargs)))
(t
ad-do-it)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment