Skip to content

Commit d899360

Browse files
committed
Minor cleanups
1 parent 8bfb99d commit d899360

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

Network/HTTP/Proxy.hs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,36 @@ runProxySettingsSocket set sock = do
105105
--
106106
-- > defaultProxySettings { proxyPort = 3128 }
107107
data Settings = Settings
108-
{ proxyPort :: Int -- ^ Port to listen on. Default value: 3100
109-
, proxyHost :: HostPreference -- ^ Default value: HostIPv4
110-
, proxyOnException :: SomeException -> Wai.Response -- ^ What to do with exceptions thrown by either the application or server. Default: ignore server-generated exceptions (see 'InvalidRequest') and print application-generated applications to stderr.
111-
, proxyTimeout :: Int -- ^ Timeout value in seconds. Default value: 30
112-
, proxyRequestModifier :: Request -> IO (Either Response Request) -- ^ A function that allows the request to be modified before being run. Default: 'return . Right'.
113-
, proxyLogger :: ByteString -> IO () -- ^ A function for logging proxy internal state. Default: 'return ()'.
114-
, proxyUpstream :: Maybe UpstreamProxy -- ^ Optional upstream proxy.
108+
{ proxyPort :: Int
109+
-- ^ Port to listen on. Default value: 3100
110+
, proxyHost :: HostPreference
111+
-- ^ Default value: HostIPv4
112+
, proxyOnException :: SomeException -> Wai.Response
113+
-- ^ What to do with exceptions thrown by either the application or server.
114+
-- Default: ignore server-generated exceptions (see 'InvalidRequest') and print
115+
-- application-generated applications to stderr.
116+
, proxyTimeout :: Int
117+
-- ^ Timeout value in seconds. Default value: 30
118+
, proxyRequestModifier :: Request -> IO (Either Response Request)
119+
-- ^ A function that allows the request to be modified before being run. Default: 'return . Right'.
120+
-- This only works for unencrypted HTTP requests (eg to upgrade the request to HTTPS) because
121+
-- HTTPS requests are encrypted.
122+
, proxyLogger :: ByteString -> IO ()
123+
-- ^ A function for logging proxy internal state. Default: 'return ()'.
124+
, proxyUpstream :: Maybe UpstreamProxy
125+
-- ^ Optional upstream proxy.
115126
}
116127

117128
-- | A http-proxy can be configured to use and upstream proxy by providing the
118129
-- proxy name, the port it listens to and an option username and password for
119130
-- proxy authorisation.
120131
data UpstreamProxy = UpstreamProxy
121-
{ upstreamHost :: ByteString -- ^ The upstream proxy's hostname.
122-
, upstreamPort :: Int -- ^ The upstream proxy's port number.
123-
, upstreamAuth :: Maybe (ByteString, ByteString) -- ^ Optional username and password to use with upstream proxy.
132+
{ upstreamHost :: ByteString
133+
-- ^ The upstream proxy's hostname.
134+
, upstreamPort :: Int
135+
-- ^ The upstream proxy's port number.
136+
, upstreamAuth :: Maybe (ByteString, ByteString)
137+
-- ^ Optional username and password to use with upstream proxy.
124138
}
125139

126140

@@ -147,9 +161,9 @@ defaultProxySettings = Settings
147161

148162
defaultExceptionResponse :: SomeException -> Wai.Response
149163
defaultExceptionResponse e =
150-
Wai.responseLBS HT.internalServerError500
151-
[ (HT.hContentType, "text/plain; charset=utf-8") ]
152-
$ LBS.fromChunks [BS.pack $ show e]
164+
Wai.responseLBS HT.internalServerError500
165+
[ (HT.hContentType, "text/plain; charset=utf-8") ]
166+
$ LBS.fromChunks [BS.pack $ show e]
153167

154168
-- -----------------------------------------------------------------------------
155169
-- Application == Wai.Request -> (Wai.Response -> IO Wai.ResponseReceived) -> IO Wai.ResponseReceived
@@ -197,13 +211,7 @@ doUpstreamRequest settings mgr respond mwreq
197211
errorResponse = proxyOnException settings . toException
198212

199213

200-
-- handleConnect :: Wai.Request -> ConduitT IO BS.ByteString -> ConduitT BS.ByteString IO () -> IO ()
201-
202-
handleConnect :: Wai.Request
203-
-> ConduitT () ByteString IO ()
204-
-> ConduitT ByteString Void IO a
205-
-> IO ()
206-
214+
handleConnect :: Wai.Request -> ConduitT () ByteString IO () -> ConduitT ByteString Void IO a -> IO ()
207215
handleConnect wreq fromClient toClient = do
208216
let (host, port) =
209217
case BS.break (== ':') $ Wai.rawPathInfo wreq of

Network/HTTP/Proxy/Request.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Network.HTTP.Proxy.Request
1515
where
1616

1717
import Data.ByteString.Char8 (ByteString)
18-
import Data.Maybe
18+
import Data.Maybe (fromMaybe)
1919
import Network.HTTP.Types (Method)
2020

2121
import qualified Network.HTTP.Types as HT

0 commit comments

Comments
 (0)