hackage-proxy 0.2.0.2 → 0.3.0
raw patch · 2 files changed
+21/−14 lines, 2 filesdep +http-clientdep +http-client-conduitdep ~conduitdep ~http-conduitdep ~wai
Dependencies added: http-client, http-client-conduit
Dependency ranges changed: conduit, http-conduit, wai, warp
Files
- HackageProxy.hs +14/−9
- hackage-proxy.cabal +7/−5
HackageProxy.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE ViewPatterns #-} module HackageProxy where -import Blaze.ByteString.Builder (fromByteString)+import Blaze.ByteString.Builder (fromByteString, fromLazyByteString) import BasicPrelude import qualified Codec.Archive.Tar as Tar import Codec.Compression.GZip (compress)@@ -16,8 +16,10 @@ import Data.Conduit.Zlib (ungzip) import Data.Text (breakOnEnd) import Network.HTTP.Conduit+import Network.HTTP.Client (responseOpen, responseClose)+import Network.HTTP.Client.Conduit (bodyReaderSource) import Network.HTTP.Types (status200)-import Network.Wai (Response (ResponseSource), pathInfo,+import Network.Wai (responseSourceBracket, pathInfo, rawPathInfo, responseLBS) import Network.Wai.Handler.Warp (run) import System.FilePath (takeExtension)@@ -49,19 +51,22 @@ -- that we're /not/ using withManager: we want to reuse the original -- ResourceT of the WAI app so that we can keep resources open from the -- request to response.- app baseReq waiReq = bracket (lift $ newManager def) (lift . closeManager) $ \man -> do- res <- http req man- (src, _) <- unwrapResumable $ responseBody res+ app baseReq waiReq =+ bracket (newManager conduitManagerSettings) closeManager $ \man -> do+ responseSourceBracket (responseOpen req man) responseClose $ \res -> do+ let src = bodyReaderSource $ responseBody res - let resStatus = responseStatus res+ resStatus = responseStatus res resHeaders = (filter ((`HashSet.member` safeResponseHeaders) . fst) (responseHeaders res)) - if isTarball res+ src' <- if isTarball res then do lbs <- L.fromChunks <$> lazyConsume (src $= ungzip) entries <- mapEntries tweakEntry $ Tar.read lbs- return $ responseLBS resStatus resHeaders (compress $ Tar.write entries)- else return $ ResponseSource resStatus resHeaders (mapOutput (Chunk . fromByteString) src)+ return $ yield $ Chunk $ fromLazyByteString $ compress $ Tar.write entries+ else return $ mapOutput (Chunk . fromByteString) src++ return (resStatus, resHeaders, src') where isTarball res = ".tar.gz" `S.isSuffixOf` rawPathInfo waiReq
hackage-proxy.cabal view
@@ -1,5 +1,5 @@ name: hackage-proxy-version: 0.2.0.2+version: 0.3.0 synopsis: Provide a proxy for Hackage which modifies responses in some way. description: The motivating use case for this is testing packages with newer versions of GHC. In this case, upper bounds on base, process, and a few other packages will often prevent compilation. This proxy will allow you to strip those upper bounds and proceed with compilation. In the future, other features may be added as well, such as package replacement. homepage: http://github.com/snoyberg/hackage-proxy@@ -18,12 +18,14 @@ build-depends: base >= 4.5 && < 5 , basic-prelude >= 0.3.6 , Cabal >= 1.12- , wai >=1.3- , warp >=1.3- , http-conduit >=1.9+ , wai >= 2.0+ , warp >= 2.0+ , http-conduit >= 2.0+ , http-client >= 0.2+ , http-client-conduit >= 0.2 , transformers >= 0.2 , case-insensitive- , conduit >= 0.5+ , conduit >= 1.0 , tar >=0.4 , filepath , blaze-builder >= 0.3