From ffb24509d79d0aad6a5fff816b00ffe7e55301b0 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Sat, 2 Jun 2018 23:27:49 +0200 Subject: [PATCH] handle http(s):// --- src/Data/Conduit/SmartSource.hs | 16 ++++++++-------- test/Spec.hs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Data/Conduit/SmartSource.hs b/src/Data/Conduit/SmartSource.hs index 5fa34c2..4558c84 100644 --- a/src/Data/Conduit/SmartSource.hs +++ b/src/Data/Conduit/SmartSource.hs @@ -71,15 +71,15 @@ getSmartSourceSpec defaultDirectory defaultFile spec smartSource (FilePathSpec filePath) = sourceFile filePath smartSource Stdin = sourceHandle stdin smartSource NoSource = error $ "should not be here" +smartSource (Http url) = httpSource url +smartSource (Https url) = httpSource url --- httpSource :: MonadResource m => String -> ConduitM () S.ByteString m () --- httpSource url = do --- request <- liftIO $ parseRequest url --- manager <- liftIO $ newManager tlsManagerSettings --- response <- lift $ http request manager --- (httpsource, finalizer) <- lift $ unwrapResumable (responseBody response) --- httpsource --- lift finalizer +httpSource :: MonadResource m => String -> ConduitM () S.ByteString m () +httpSource url = do + request <- liftIO $ parseRequest url + manager <- liftIO $ newManager tlsManagerSettings + response <- lift $ http request manager + responseBody response checkRefFormat :: String -> Bool checkRefFormat ref = diff --git a/test/Spec.hs b/test/Spec.hs index 9658a4e..10c9ce0 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -309,8 +309,8 @@ main = hspec $ do getSmartSourceSpec "foo" "in.tsv" "https://gonito.net" `shouldReturn` (Right $ Https "https://gonito.net") it "sources are accessed" $ do readFromSmartSource "baz" "out.tsv" "test/files/foo.txt" `shouldReturn` ["foo\n"] --- readFromSmartSource [] Nothing "https://httpbin.org/robots.txt" `shouldReturn` --- ["User-agent: *\nDisallow: /deny\n"] + readFromSmartSource "" "" "https://httpbin.org/robots.txt" `shouldReturn` + ["User-agent: *\nDisallow: /deny\n"] readFromSmartSource :: FilePath -> FilePath -> String -> IO [String] readFromSmartSource defaultDir defaultFile specS = do