http-reverse-proxy 0.1.0.1 → 0.1.0.2
raw patch · 3 files changed
+34/−18 lines, 3 filesdep ~bytestringdep ~warpPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: bytestring, warp
API changes (from Hackage documentation)
Files
- Network/HTTP/ReverseProxy.hs +8/−6
- http-reverse-proxy.cabal +3/−2
- test/main.hs +23/−10
Network/HTTP/ReverseProxy.hs view
@@ -26,7 +26,7 @@ import Control.Concurrent.MVar.Lifted (newEmptyMVar, putMVar, takeMVar) import Control.Concurrent.Lifted (fork, killThread) import Control.Monad.Trans.Control (MonadBaseControl)-import Network.Wai.Handler.Warp (defaultSettings, Connection (..), parseRequest, sendResponse)+import Network.Wai.Handler.Warp (defaultSettings, Connection (..), parseRequest, sendResponse, dummyCleaner) import Data.Conduit.Binary (sourceFileRange) import qualified Data.IORef as I import Network.Socket (PortNumber (PortNum), SockAddr (SockAddrInet))@@ -180,7 +180,7 @@ (fromClient', keepAlive) <- runResourceT $ do (req, fromClient') <- parseRequest conn 0 dummyAddr fromClient res <- app req- keepAlive <- sendResponse (error "cleaner") req conn res+ keepAlive <- sendResponse dummyCleaner req conn res (fromClient'', _) <- liftIO fromClient' >>= unwrapResumable return (fromClient'', keepAlive) if keepAlive@@ -191,10 +191,12 @@ conn = Connection { connSendMany = \bss -> mapM_ yield bss $$ toClient , connSendAll = \bs -> yield bs $$ toClient- , connSendFile = \fp offset len th headers _cleaner ->- runResourceT $ sourceFileRange fp (Just offset) (Just len)- $$ mapM (\bs -> lift th >> return bs)- =$ transPipe lift toClient+ , connSendFile = \fp offset len _th headers _cleaner ->+ let src1 = mapM_ yield headers+ src2 = sourceFileRange fp (Just offset) (Just len)+ in runResourceT+ $ (src1 >> src2)+ $$ transPipe lift toClient , connClose = return () , connRecv = error "connRecv should not be used" }
http-reverse-proxy.cabal view
@@ -1,5 +1,5 @@ name: http-reverse-proxy-version: 0.1.0.1+version: 0.1.0.2 synopsis: Reverse proxy HTTP requests, either over raw sockets or with WAI description: Provides a simple means of reverse-proxying HTTP requests. The raw approach uses the same technique as leveraged by keter, whereas the WAI approach performs full request/response parsing via WAI and http-conduit. homepage: https://github.com/fpco/http-reverse-proxy@@ -28,7 +28,7 @@ , classy-prelude-conduit >= 0.3 , network , conduit >= 0.5- , warp >= 1.3+ , warp >= 1.3.4 test-suite test type: exitcode-stdio-1.0@@ -42,6 +42,7 @@ , http-types , hspec >= 1.3 , warp >= 1.3+ , bytestring source-repository head type: git
test/main.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE OverloadedStrings #-}-import Control.Concurrent (forkIO, threadDelay)-import Data.Conduit.Network (serverSettings, runTCPServer)-import qualified Network.HTTP.Conduit as HC-import Network.HTTP.ReverseProxy (ProxyDest (..), defaultOnExc,- rawProxyTo, waiProxyTo, waiToRaw)-import Network.HTTP.Types (status200)-import Network.Wai (responseLBS)-import Network.Wai.Handler.Warp (run)-import Test.Hspec (describe, hspec, it, shouldBe)+import Control.Concurrent (forkIO, threadDelay)+import qualified Data.ByteString.Lazy.Char8 as L8+import Data.Conduit.Network (serverSettings, runTCPServer)+import qualified Network.HTTP.Conduit as HC+import Network.HTTP.ReverseProxy (ProxyDest (..), defaultOnExc,+ rawProxyTo, waiProxyTo, waiToRaw)+import Network.HTTP.Types (status200)+import Network.Wai (responseLBS, Response (ResponseFile))+import Network.Wai.Handler.Warp (run)+import Test.Hspec (describe, hspec, it, shouldBe) main :: IO () main = hspec $ do@@ -21,7 +22,8 @@ threadDelay 100000 lbs <- HC.simpleHttp "http://localhost:5002" lbs `shouldBe` content- it "waiToRaw" $ do+ describe "waiToRaw" $ do+ it "works" $ do let content = "waiToRaw" manager <- HC.newManager HC.def let waiApp = const $ return $ responseLBS status200 [] content@@ -30,3 +32,14 @@ threadDelay 100000 lbs <- HC.simpleHttp "http://localhost:6000" lbs `shouldBe` content+ it "sends files" $ do+ let content = "PONG"+ fp = "pong"+ writeFile fp content+ manager <- HC.newManager HC.def+ let waiApp = const $ return $ ResponseFile status200 [] fp Nothing+ rawApp = waiToRaw waiApp+ forkIO $ runTCPServer (serverSettings 6001 "*") (rawProxyTo (const $ return $ Left rawApp))+ threadDelay 100000+ lbs <- HC.simpleHttp "http://localhost:6001"+ lbs `shouldBe` L8.pack content