forked from snoyberg/http-conduit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.hs
40 lines (38 loc) · 1.21 KB
/
test.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
import Network.HTTP.Conduit
import Network
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
import System.Environment.UTF8 (getArgs, getEnv)
import Data.CaseInsensitive (original)
import Data.Conduit
import Control.Monad.IO.Class (liftIO)
import Control.Exception (finally)
import Network.Socks5 (SocksConf(..), defaultSocksConf)
mproxify sockshost req
| sockshost == "" = req
| otherwise = req { socksProxy = Just $ defaultSocksConf sockshost 1080 }
main :: IO ()
main = withSocketsDo $ do
[url] <- getArgs
proxy <- catch (getEnv "SOCKS_PROXY") (const $ return "")
_req2 <- mproxify proxy `fmap` parseUrl url
{-
let req = urlEncodedBody
[ ("foo", "bar")
, ("baz%%38**.8fn", "bin")
] _req2
-}
flip finally printOpenSockets $ runResourceT $ do
man <- newManager
Response sc hs b <- httpLbs _req2 man
liftIO $ do
print sc
mapM_ (\(x, y) -> do
S.putStr $ original x
putStr ": "
S.putStr y
putStrLn "") hs
putStrLn ""
L.putStr b