summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaelSnoyman <>2012-02-03 12:10:45 (GMT)
committerhdiff <hdiff@luite.com>2012-02-03 12:10:45 (GMT)
commit0df6becf06fadf2000aeaaebcd25b894907ac0d5 (patch)
tree442ce77a45823213c4a188af69af1c60b33c7a0c
parentf25dfb04f46f76458ff98ed1936beeeb4575b1c7 (diff)
version 1.2.31.2.3
-rw-r--r--Network/HTTP/Conduit.hs1
-rw-r--r--Network/HTTP/Conduit/ConnInfo.hs8
-rw-r--r--Network/HTTP/Conduit/Manager.hs28
-rw-r--r--Network/HTTP/Conduit/Request.hs4
-rw-r--r--http-conduit.cabal4
5 files changed, 33 insertions, 12 deletions
diff --git a/Network/HTTP/Conduit.hs b/Network/HTTP/Conduit.hs
index 8bfc2eb..96debd7 100644
--- a/Network/HTTP/Conduit.hs
+++ b/Network/HTTP/Conduit.hs
@@ -68,6 +68,7 @@ module Network.HTTP.Conduit
, requestHeaders
, requestBody
, proxy
+ , socksProxy
, rawBody
, decompress
, redirectCount
diff --git a/Network/HTTP/Conduit/ConnInfo.hs b/Network/HTTP/Conduit/ConnInfo.hs
index 1ee2624..cd45e42 100644
--- a/Network/HTTP/Conduit/ConnInfo.hs
+++ b/Network/HTTP/Conduit/ConnInfo.hs
@@ -28,9 +28,11 @@ import Data.ByteString (ByteString)
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
+import Network (PortID(..))
import Network.Socket (Socket, sClose)
import Network.Socket.ByteString (recv, sendAll)
import qualified Network.Socket as NS
+import Network.Socks5 (socksConnectWith, SocksConf)
import Network.TLS
import Network.TLS.Extra (ciphersuite_all)
@@ -154,8 +156,10 @@ sslClientConn _desc onCerts h = do
-- least on tls-0.8.4 it's guaranteed to always
-- return a lazy bytestring with a single chunk.
-getSocket :: String -> Int -> IO NS.Socket
-getSocket host' port' = do
+getSocket :: String -> Int -> Maybe SocksConf -> IO NS.Socket
+getSocket host' port' (Just socksConf) = do
+ socksConnectWith socksConf host' (PortNumber $ fromIntegral port')
+getSocket host' port' Nothing = do
let hints = NS.defaultHints {
NS.addrFlags = [NS.AI_ADDRCONFIG]
, NS.addrSocketType = NS.Stream
diff --git a/Network/HTTP/Conduit/Manager.hs b/Network/HTTP/Conduit/Manager.hs
index 1c45d46..67c704d 100644
--- a/Network/HTTP/Conduit/Manager.hs
+++ b/Network/HTTP/Conduit/Manager.hs
@@ -18,7 +18,7 @@ module Network.HTTP.Conduit.Manager
import Prelude hiding (catch)
import Data.Monoid (mappend)
-import System.IO (hClose, hFlush)
+import System.IO (hClose, hFlush, IOMode(..))
import qualified Data.IORef as I
import qualified Data.Map as Map
@@ -42,7 +42,8 @@ import Control.Monad.Trans.Resource
import Control.Concurrent (forkIO, threadDelay)
import Data.Time (UTCTime, getCurrentTime, addUTCTime)
-import Network (connectTo, PortID (PortNumber))
+import Network (connectTo, PortID (PortNumber), HostName)
+import Network.Socket (socketToHandle)
import Data.Certificate.X509 (X509, encodeCertificate)
import qualified Network.HTTP.Types as W
@@ -52,8 +53,10 @@ import Network.HTTP.Conduit.ConnInfo
import Network.HTTP.Conduit.Util (hGetSome)
import Network.HTTP.Conduit.Parser (parserHeadersFromByteString)
import Network.HTTP.Conduit.Request
+import Network.Socks5 (SocksConf, socksConnectWith)
import Data.Default
import Data.Maybe (mapMaybe)
+import System.IO (Handle)
-- | Settings for a @Manager@. Please use the 'def' function and then modify
-- individual settings.
@@ -238,10 +241,11 @@ getSocketConn
=> Manager
-> String
-> Int
+ -> Maybe SocksConf -- ^ optional socks proxy
-> ResourceT m (ConnRelease m, ConnInfo, ManagedConn)
-getSocketConn man host' port' =
+getSocketConn man host' port' socksProxy' =
getManagedConn man (ConnKey (T.pack host') port' False) $
- getSocket host' port'>>= socketConn desc
+ getSocket host' port' socksProxy' >>= socketConn desc
where
desc = socketDesc host' port' "unsecured"
@@ -253,10 +257,11 @@ getSslConn :: ResourceIO m
-> Manager
-> String -- ^ host
-> Int -- ^ port
+ -> Maybe SocksConf -- ^ optional socks proxy
-> ResourceT m (ConnRelease m, ConnInfo, ManagedConn)
-getSslConn checkCert man host' port' =
+getSslConn checkCert man host' port' socksProxy' =
getManagedConn man (ConnKey (T.pack host') port' True) $
- (connectTo host' (PortNumber $ fromIntegral port') >>= sslClientConn desc checkCert)
+ (connectionTo host' (PortNumber $ fromIntegral port') socksProxy' >>= sslClientConn desc checkCert)
where
desc = socketDesc host' port' "secured"
@@ -268,14 +273,15 @@ getSslProxyConn
-> Manager
-> String -- ^ Proxy host
-> Int -- ^ Proxy port
+ -> Maybe SocksConf -- ^ optional SOCKS proxy
-> ResourceT m (ConnRelease m, ConnInfo, ManagedConn)
-getSslProxyConn checkCert thost tport man phost pport =
+getSslProxyConn checkCert thost tport man phost pport socksProxy' =
getManagedConn man (ConnKey (T.pack phost) pport True) $
doConnect >>= sslClientConn desc checkCert
where
desc = socketDesc phost pport "secured-proxy"
doConnect = do
- h <- connectTo phost (PortNumber $ fromIntegral pport)
+ h <- connectionTo phost (PortNumber $ fromIntegral pport) socksProxy'
L.hPutStr h $ Blaze.toLazyByteString connectRequest
hFlush h
r <- hGetSome h 2048
@@ -350,7 +356,7 @@ getConn :: ResourceIO m
-> Manager
-> ResourceT m (ConnRelease m, ConnInfo, ManagedConn)
getConn req m =
- go m connhost connport
+ go m connhost connport (socksProxy req)
where
h = host req
(useProxy, connhost, connport) =
@@ -401,3 +407,7 @@ checkCerts man host' certs = do
Nothing -> Map.singleton encoded expire
Just m -> Map.insert encoded expire m
+connectionTo :: HostName -> PortID -> Maybe SocksConf -> IO Handle
+connectionTo host' port' Nothing = connectTo host' port'
+connectionTo host' port' (Just socksConf) =
+ socksConnectWith socksConf host' port' >>= flip socketToHandle ReadWriteMode
diff --git a/Network/HTTP/Conduit/Request.hs b/Network/HTTP/Conduit/Request.hs
index e6e8876..854fbc6 100644
--- a/Network/HTTP/Conduit/Request.hs
+++ b/Network/HTTP/Conduit/Request.hs
@@ -36,6 +36,7 @@ import qualified Data.ByteString.Char8 as S8
import qualified Data.ByteString.Lazy as L
import qualified Network.HTTP.Types as W
+import Network.Socks5 (SocksConf)
import Control.Exception (Exception, SomeException, toException)
import Control.Failure (Failure (failure))
@@ -72,6 +73,8 @@ data Request m = Request
, requestBody :: RequestBody m
, proxy :: Maybe Proxy
-- ^ Optional HTTP proxy.
+ , socksProxy :: Maybe SocksConf
+ -- ^ Optional SOCKS proxy.
, rawBody :: Bool
-- ^ If @True@, a chunked and\/or gzipped body will not be
-- decoded. Use with caution.
@@ -165,6 +168,7 @@ instance Default (Request m) where
, requestBody = RequestBodyLBS L.empty
, method = "GET"
, proxy = Nothing
+ , socksProxy = Nothing
, rawBody = False
, decompress = browserDecompress
, redirectCount = 10
diff --git a/http-conduit.cabal b/http-conduit.cabal
index e665885..8ec0f06 100644
--- a/http-conduit.cabal
+++ b/http-conduit.cabal
@@ -1,5 +1,5 @@
name: http-conduit
-version: 1.2.2
+version: 1.2.3
license: BSD3
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
@@ -43,6 +43,7 @@ library
, text
, transformers-base >= 0.4 && < 0.5
, lifted-base >= 0.1 && < 0.2
+ , socks >= 0.4 && < 0.5
, time
if flag(network-bytestring)
build-depends: network >= 2.2.1 && < 2.2.3
@@ -96,6 +97,7 @@ test-suite test
, network
, wai
, warp
+ , socks
, http-types
source-repository head