Skip to content

Commit

Permalink
Network.HTTP.Proxy: Expose httpProxyApp
Browse files Browse the repository at this point in the history
This allows the `Application` to be used by other projects.
  • Loading branch information
erikd committed Nov 16, 2016
1 parent fc7f2db commit ddf327c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Network/HTTP/Proxy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module Network.HTTP.Proxy
, Settings (..)
, UpstreamProxy (..)

, httpProxyApp

, runProxy
, runProxySettings
, runProxySettingsSocket
Expand Down Expand Up @@ -79,7 +81,7 @@ runProxy port = runProxySettings $ defaultProxySettings { proxyPort = port }
runProxySettings :: Settings -> IO ()
runProxySettings set = do
mgr <- HC.newManager HC.tlsManagerSettings
Warp.runSettings (warpSettings set) $ proxyApp set mgr
Warp.runSettings (warpSettings set) $ httpProxyApp set mgr

-- | Run a HTTP and HTTPS proxy server with the specified settings but provide
-- it with a Socket to accept connections on. The Socket should have already
Expand All @@ -90,7 +92,7 @@ runProxySettingsSocket set sock = do
port <- socketPort sock
mgr <- HC.newManager HC.tlsManagerSettings
Warp.runSettingsSocket (warpSettings set) sock
$ proxyApp set { proxyPort = fromIntegral port } mgr
$ httpProxyApp set { proxyPort = fromIntegral port } mgr

-- | Various proxy server settings. This is purposely kept as an abstract data
-- type so that new settings can be added without breaking backwards
Expand Down Expand Up @@ -146,9 +148,10 @@ defaultExceptionResponse e =
$ LBS.fromChunks [BS.pack $ show e]

-- -----------------------------------------------------------------------------
-- Application == Wai.Request -> (Wai.Response -> IO Wai.ResponseReceived) -> IO Wai.ResponseReceived

proxyApp :: Settings -> HC.Manager -> Wai.Request -> (Wai.Response -> IO Wai.ResponseReceived) -> IO Wai.ResponseReceived
proxyApp settings mgr wreq respond = do
httpProxyApp :: Settings -> HC.Manager -> Application
httpProxyApp settings mgr wreq respond = do
mwreq <- proxyRequestModifier settings $ proxyRequest wreq
either respond (doUpstreamRequest settings mgr respond . waiRequest wreq) mwreq

Expand Down

0 comments on commit ddf327c

Please sign in to comment.