Using Haskell SimpleHTTP with a proxy server?

I am trying to figure out how to make a basic GET request using Network.HTTP.simpleHTTP, which will use a proxy.

I tried to set the http_proxy environment variable, and I think I understand how to make a proxy server using Network.HTTP.Proxy. But there is nothing in the Hackage API on how to set up a simple HTTTP call or request type to use a proxy server.

The current code I have is:

import Network.HTTP import Network.HTTP.Proxy import Data.Maybe main = do let proxy = fromJust $ parseProxy "proxyserver.foo.com:80" x <- simpleHTTP (getRequest "http://www.google.com") >>= getResponseBody print x 
+6
proxy haskell networking
source share
1 answer

In the documentation for simpleHTTP :

simpleHTTP req transmits Request req , opening a direct, intermittent connection to the HTTP server ... If you need to notify the request through an HTTP proxy, you will have to normalize the request yourself. Or switch to using Network.Browser instead.

I'm not quite sure what the authors mean by "normalize the query yourself" here. I do not see how this is possible with simpleHTTP in Network.HTTP . I think you will need to use the one that is in Network.HTTP.HandleStream .

So why not just use Network.Browser ? It is very comfortable:

 import Control.Applicative ((<$>)) import Data.Maybe (fromJust) import Network.Browser import Network.HTTP import Network.HTTP.Proxy (parseProxy) main = do rsp <- browse $ do setProxy . fromJust $ parseProxy "127.0.0.1:8118" request $ getRequest "http://www.google.com" print $ rspBody <$> rsp 
+9
source

All Articles