ocaml-cohttp icon indicating copy to clipboard operation
ocaml-cohttp copied to clipboard

HTTP(S)/SOCKS5 Proxy support

Open sgrove opened this issue 8 years ago • 4 comments

I need to use SOCKS5 and HTTP proxies with Cohttp. I'm not sure if support belongs in the library proper, or another library with a bit of glue to work with Cohttp.

Is this possible currently?

sgrove avatar Nov 22 '16 18:11 sgrove

I'm tempted to suggest it belongs in a separate library that can be instantiated in a separate unikernel to the webserver in any deployment; but I don't know if that would fit with what the use you have in mind :)

(That may make more sense for SOCKS5 than HTTP proxy I guess. https://github.com/cfcs/ocaml-socks may also be relevant.)

mor1 avatar Nov 22 '16 20:11 mor1

My use case is simply that when I make an http request, I need it to go through a proxy (hosted on another machine, of course). For example, with the most popular Clojure http client's proxy support, it's simply a matter of passing in some extra named arguments (or the equivalent thereof):

;; No proxy, request will be directly between this machine and foo.com
(client/get "http://foo.com")

;; Request will go through HTTP proxy myproxyhost.com:8118
(client/get "http://foo.com" {:proxy-host "myproxyhost.com" :proxy-port 8118})

;; Request will go through SOCKS proxy 
(client/get "http://foo.com"
            {:connection-manager
             (conn-mgr/make-socks-proxied-conn-manager "mysocksproxyhost.com" 8081)})

Connections can also be stored and reused elsewhere, which can be useful for a number of different things.

What would the equivalent look like with Cohttp?

sgrove avatar Nov 22 '16 20:11 sgrove

I'm also interested if you have some informations about that.

tobiasBora avatar Apr 01 '17 01:04 tobiasBora

With Go's example:

proxyUrl, err := url.Parse("http://proxyIp:proxyPort")
myClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}}

It's been nearly 2 years since @sgrove post this issue firstly, but there's still no answer for this common issue. I think this is one of the reason that keep people far away from OCaml.

impvd avatar Sep 12 '18 12:09 impvd