0

Like with FoxyProxy, I want to use proxy in emacs only for URLs that match a specific regexp.

E.g., if the URL matches \\.ec2\\.internal, I want the url-proxy-services to be "ip-10-0-37-237.ec2.internal:8081", otherwise none.

Note that the no_proxy key works the other way around - it excludes matching URLs from proxy processing, while I want to only include some URLs.

sds
  • 5,928
  • 20
  • 39

1 Answers1

0

Package url-proxy provides a defvar called url-proxy-locator that allows you to define your own locator.

(defun locate-my-url-proxy (urlobj host)
  (cond
   ((string-match-p "\\.ec2\\.internal" host)
    "PROXY ip-10-0-37-237.ec2.internal:8081")
   (t "DIRECT")))

;;; returns "http://ip-10-0-37-237.ec2.internal:8081/"
(let ((url-proxy-locator #'locate-my-url-proxy)
      (urlobj (url-generic-parse-url "https://sldjf.ec2.internal/jdsklfj")))
  (url-find-proxy-for-url urlobj (url-host urlobj)))
TerryTsao
  • 1,176
  • 4
  • 18