packages feed

http-directory 0.1.9 → 0.1.10

raw patch · 6 files changed

+109/−36 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Network.HTTP.Directory: httpFileHeaders :: Manager -> String -> IO ResponseHeaders
+ Network.HTTP.Directory: httpFileHeaders' :: String -> IO ResponseHeaders
+ Network.HTTP.Directory: httpFileSizeTime :: Manager -> String -> IO (Maybe Integer, Maybe UTCTime)
+ Network.HTTP.Directory: httpFileSizeTime' :: String -> IO (Maybe Integer, Maybe UTCTime)

Files

CHANGELOG.md view
@@ -2,6 +2,9 @@  `http-directory` uses [PVP Versioning](https://pvp.haskell.org). +## 0.1.10 (2022-06-11)+- add httpFileSizeTime and httpFileHeaders+ ## 0.1.9 (2021-12-09) - httpDirectory' now uses Network.HTTP.Simple - also add httpRawDirectory', httpExists', httpFileSize', httpLastModified'
README.md view
@@ -2,7 +2,7 @@  [![Hackage](https://img.shields.io/hackage/v/http-directory.svg)](https://hackage.haskell.org/package/http-directory) [![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)-[![Stackage Lts](http://stackage.org/package/http-directory/badge/lts)](http://stackage.org/lts/package/http-directory)+[![Stackage LTS](http://stackage.org/package/http-directory/badge/lts)](http://stackage.org/lts/package/http-directory) [![Stackage Nightly](http://stackage.org/package/http-directory/badge/nightly)](http://stackage.org/nightly/package/http-directory)  A simple library for reading http directories.@@ -13,6 +13,9 @@ The library is intended for listing the files in http file directories, but since http directories are just html pages it can also be used to list the links (href's) on any html webpage.++Additionally there are methods for checking the size and modification time,+and a few other helper functions.  ## Usage examples 
example/Makefile view
@@ -2,6 +2,10 @@  latest-ghc: latest-ghc.hs 	ghc latest-ghc+	./latest-ghc  list-page: list-page.hs 	ghc list-page+	./list-page https://download.fedoraproject.org/pub/fedora/linux+clean:+	rm -f *.o *.hi latest-ghc list-page
http-directory.cabal view
@@ -1,18 +1,18 @@ cabal-version:       1.18 name:                http-directory-version:             0.1.9+version:             0.1.10 synopsis:            http directory listing library description:             Library for listing the files (href's) in an http directory.             It can also check the size, existence, modtime of files,-            and for url redirects.+            and url redirects. homepage:            https://github.com/juhp/http-directory bug-reports:         https://github.com/juhp/http-directory/issues license:             MIT license-file:        LICENSE author:              Jens Petersen maintainer:          juhpetersen@gmail.com-copyright:           2019-2021 Jens Petersen+copyright:           2019-2022 Jens Petersen category:            Network build-type:          Simple extra-doc-files:     README.md@@ -20,9 +20,9 @@                    , example/Makefile                    , example/latest-ghc.hs                    , example/list-page.hs-tested-with:         GHC== 7.4.2 || == 7.6.3 || == 7.8.4 || == 7.10.3-                     || == 8.0.2 || == 8.2.2 || == 8.4.4 || == 8.6.5-                     || == 8.8.4 || == 8.10.5+tested-with:         GHC== 7.8.4 || == 7.10.3 || == 8.0.2 || == 8.2.2+                     || == 8.4.4 || == 8.6.5  || == 8.8.4 || == 8.10.7+                     || == 9.0.2  source-repository head   type:                git
src/Network/HTTP/Directory.hs view
@@ -10,11 +10,11 @@  main = do   let url = \"https:\/\/example.com\/some\/dir\/\"-  files <- 'httpDirectory\'' url+  files <- httpDirectory\' url   mapM_ T.putStrLn files   let file = url '+/+' T.unpack (head files)-  'httpFileSize\'' file >>= print-  'httpLastModified\'' file >>= print+  httpFileSize\' file >>= print+  httpLastModified\' file >>= print @  The main methods use http-client and most of the primed ones http-conduit.@@ -31,6 +31,10 @@          httpFileSize',          httpLastModified,          httpLastModified',+         httpFileSizeTime,+         httpFileSizeTime',+         httpFileHeaders,+         httpFileHeaders',          httpManager,          httpRedirect,          httpRedirect',@@ -50,6 +54,9 @@  import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Lazy.Char8 as BL+#if MIN_VERSION_base(4,11,0)+import Data.Functor ((<&>))+#endif import qualified Data.List as L import Data.Maybe import Data.Text (Text)@@ -63,7 +70,8 @@ import Network.HTTP.Client.TLS (tlsManagerSettings) import Network.HTTP.Date (httpDateToUTC, parseHTTPDate) import qualified Network.HTTP.Simple as S-import Network.HTTP.Types (hContentLength, hLocation, methodHead, statusCode)+import Network.HTTP.Types (hContentLength, hLocation, hLastModified,+                           methodHead, statusCode, ResponseHeaders) import Network.URI (parseURI, URI(..))  import Text.HTML.DOM (parseLBS)@@ -111,7 +119,7 @@     nonTrailingSlash t =       (T.length t > 1) && ("/" `T.isInfixOf` T.init t) --- | Like httpDirectory but uses own Manager+-- | Like httpDirectory but uses the global Manager -- -- @since 0.1.4 httpDirectory' :: String -> IO [Text]@@ -174,11 +182,9 @@ -- -- Raises an error if the http request fails. httpFileSize :: Manager -> String -> IO (Maybe Integer)-httpFileSize mgr url = do-  response <- httpHead mgr url-  checkResponse url response-  let headers = responseHeaders response-  return $ read . B.unpack <$> lookup hContentLength headers+httpFileSize mgr url =+  httpFileHeaders mgr url <&>+  fmap (read . B.unpack) . lookup hContentLength  -- | Try to get the filesize (Content-Length field) of an http file --@@ -186,11 +192,9 @@ -- -- @since 0.1.9 httpFileSize' :: String -> IO (Maybe Integer)-httpFileSize' url = do-  response <- httpHead' url-  checkResponse url response-  let headers = responseHeaders response-  return $ read . B.unpack <$> lookup hContentLength headers+httpFileSize' url =+  httpFileHeaders' url <&>+  fmap (read . B.unpack) . lookup hContentLength  -- | Try to get the modification time (Last-Modified field) of an http file --@@ -199,24 +203,70 @@ -- @since 0.1.1 httpLastModified :: Manager -> String -> IO (Maybe UTCTime) httpLastModified mgr url = do-  response <- httpHead mgr url-  checkResponse url response-  let headers = responseHeaders response-      mdate = lookup "Last-Modified" headers+  headers <- httpFileHeaders mgr url+  let mdate = lookup hLastModified headers   return $ httpDateToUTC <$> (parseHTTPDate =<< mdate)  -- | Try to get the modification time (Last-Modified field) of an http file ----- Raises an error if the http request fails.+-- Raises an error if the http request fails. Uses global Manager -- -- @since 0.1.9 httpLastModified' :: String -> IO (Maybe UTCTime) httpLastModified' url = do+  headers <- httpFileHeaders' url+  let mdate = lookup hLastModified headers+  return $ httpDateToUTC <$> (parseHTTPDate =<< mdate)++-- | Try to get the filesize and modification time of an http file+--+-- Raises an error if the http request fails.+--+-- @since 0.1.10+httpFileSizeTime :: Manager -> String -> IO (Maybe Integer, Maybe UTCTime)+httpFileSizeTime mgr url = do+  headers <- httpFileHeaders mgr url+  let msize = read . B.unpack <$> lookup hContentLength headers+      mdate = lookup hLastModified headers+      mtime = httpDateToUTC <$> (parseHTTPDate =<< mdate)+  return (msize, mtime)++-- | Try to get the filesize and modification time of an http file+-- Global Manager version.+--+-- Raises an error if the http request fails.+--+-- @since 0.1.10+httpFileSizeTime' :: String -> IO (Maybe Integer, Maybe UTCTime)+httpFileSizeTime' url = do+  headers <- httpFileHeaders' url+  let msize = read . B.unpack <$> lookup hContentLength headers+      mdate = lookup hLastModified headers+      mtime = httpDateToUTC <$> (parseHTTPDate =<< mdate)+  return (msize, mtime)++-- | Return the HTTP headers for a file+--+-- Raises an error if the http request fails.+--+-- @since 0.1.10+httpFileHeaders :: Manager -> String -> IO ResponseHeaders+httpFileHeaders mgr url = do+  response <- httpHead mgr url+  checkResponse url response+  return $ responseHeaders response++-- | Return the HTTP headers of an http file.+-- Global Manager version.+--+-- Raises an error if the http request fails.+--+-- @since 0.1.10+httpFileHeaders' :: String -> IO ResponseHeaders+httpFileHeaders' url = do   response <- httpHead' url   checkResponse url response-  let headers = responseHeaders response-      mdate = lookup "Last-Modified" headers-  return $ httpDateToUTC <$> (parseHTTPDate =<< mdate)+  return $ responseHeaders response  -- conflicts with Request checkResponse :: String -> Response r -> IO ()@@ -225,7 +275,7 @@     putStrLn url     error' $ show $ responseStatus response --- | alias for 'newManager tlsManagerSettings'+-- | Alias for 'newManager tlsManagerSettings' -- so one does not need to import http-client etc -- -- @since 0.1.2@@ -246,7 +296,7 @@ httpRedirect mgr url =   listToMaybe <$> httpRedirects mgr url --- | Like httpRedirect but uses own Manager.+-- | Like httpRedirect but uses global Manager. -- -- @since 0.1.4 httpRedirect' :: String -> IO (Maybe B.ByteString)@@ -321,3 +371,11 @@ s +/+ t | last s == '/' = init s +/+ t         | head t == '/' = s +/+ tail t s +/+ t = s ++ "/" ++ t+++#if !MIN_VERSION_base(4,11,0)+infixl 1 <&>++(<&>) :: Functor f => f a -> (a -> b) -> f b+as <&> f = f <$> as+#endif
test/Spec.hs view
@@ -102,14 +102,19 @@       isJust msize `shouldBe` True    describe "httpLastModified" $ do-    it "httpbin" $ do+    it "haskell" $ do       mgr <- httpManager-      mtime <- httpLastModified mgr "https://haskell.org/"+      mtime <- httpLastModified mgr "https://www.haskell.org/"       isJust mtime `shouldBe` True -    it "httpbin'" $ do-      mtime <- httpLastModified' "https://haskell.org/"+    it "haskell" $ do+      mtime <- httpLastModified' "https://www.haskell.org/"       isJust mtime `shouldBe` True++  describe "httpFileSizeTime" $ do+    it "haskell" $ do+      (msize, mtime) <- httpFileSizeTime' "https://www.haskell.org/"+      (isJust msize, isJust mtime) `shouldBe` (True,True)    -- https://github.com/postmanlabs/httpbin/issues/617   describe "httpRedirect" $ do