packages feed

http-directory 0.1.10 → 0.1.11

raw patch · 6 files changed

+76/−28 lines, 6 filesdep +simple-cmd-argsdep ~basenew-component:exe:http-directoryPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: simple-cmd-args

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Network.HTTP.Directory: httpFileSizeAndTime' :: String -> IO (Maybe (Integer, UTCTime))
- Network.HTTP.Directory: data Manager
+ Network.HTTP.Directory: data () => Manager

Files

CHANGELOG.md view
@@ -2,6 +2,13 @@  `http-directory` uses [PVP Versioning](https://pvp.haskell.org). +## 0.1.11 (2025-02-08)+- add httpFileSizeAndTime'+- tests: switch from httpbingo to httpbin.org/redirect+- redefine +/+ with dropWhile/End to avoid head/init/tail/last+- add simple cli tool+- remove support for ghc < 8.2 (base < 4.9)+ ## 0.1.10 (2022-06-11) - add httpFileSizeTime and httpFileHeaders 
README.md view
@@ -19,9 +19,7 @@  ## Usage examples -```haskell-Network.HTTP.Directory> :type httpDirectory'-httpDirectory' :: String -> IO [Text]+```shellsession Network.HTTP.Directory> httpDirectory' "https://hackage.haskell.org/package/base/src/System" ["CPUTime.hsc","Environment.hs","Exit.hs","IO.hs","Info.hs","Mem.hs","Timeout.hs", "CPUTime","Console","Environment","IO","Mem","Posix"]
+ app/Main.hs view
@@ -0,0 +1,13 @@+import qualified Data.Text.IO as T+import Network.HTTP.Directory+import SimpleCmdArgs (simpleCmdArgs, strArg)++main :: IO ()+main =+  simpleCmdArgs Nothing "http-directory"+  "Simple http directory lister" $+  run+  <$> strArg "URL"+  where+    run url =+      httpDirectory' url >>= mapM_ T.putStrLn
http-directory.cabal view
@@ -1,6 +1,6 @@ cabal-version:       1.18 name:                http-directory-version:             0.1.10+version:             0.1.11 synopsis:            http directory listing library description:             Library for listing the files (href's) in an http directory.@@ -12,7 +12,7 @@ license-file:        LICENSE author:              Jens Petersen maintainer:          juhpetersen@gmail.com-copyright:           2019-2022 Jens Petersen+copyright:           2019-2022,2024-2025 Jens Petersen category:            Network build-type:          Simple extra-doc-files:     README.md@@ -20,19 +20,24 @@                    , example/Makefile                    , example/latest-ghc.hs                    , example/list-page.hs-tested-with:         GHC== 7.8.4 || == 7.10.3 || == 8.0.2 || == 8.2.2+tested-with:         GHC== 8.0.2 || == 8.2.2                      || == 8.4.4 || == 8.6.5  || == 8.8.4 || == 8.10.7-                     || == 9.0.2+                     || == 9.0.2 || == 9.2.8  || == 9.4.8 || == 9.6.6+                     || == 9.8.4 || == 9.10.1  source-repository head   type:                git   location:            https://github.com/juhp/http-directory.git +flag executable+  description:   build cli tool+  default:       False+ library   hs-source-dirs:      src   exposed-modules:     Network.HTTP.Directory -  build-depends:       base < 5,+  build-depends:       base >= 4.9 && < 5,                        bytestring,                        html-conduit,                        http-client,@@ -67,6 +72,18 @@                        -Wpartial-fields   if impl(ghc >= 8.10)     ghc-options:       -Wunused-packages++executable http-directory+  main-is: app/Main.hs+  build-depends:       base < 5+                     , http-directory+                     , simple-cmd-args+                     , text+  default-language:    Haskell2010+  if flag(executable)+    Buildable:      True+  else+    Buildable:      False  test-suite test   main-is: Spec.hs
src/Network/HTTP/Directory.hs view
@@ -33,6 +33,7 @@          httpLastModified',          httpFileSizeTime,          httpFileSizeTime',+         httpFileSizeAndTime',          httpFileHeaders,          httpFileHeaders',          httpManager,@@ -46,10 +47,6 @@          (+/+)        ) where -#if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,8,0))-#else-import Control.Applicative ((<$>))-#endif import Control.Monad (when)  import qualified Data.ByteString.Char8 as B@@ -232,6 +229,7 @@   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.@@ -245,6 +243,25 @@       mtime = httpDateToUTC <$> (parseHTTPDate =<< mdate)   return (msize, mtime) +-- | Try to get the filesize and modification time together of an http file+-- Unlike httpFileSizeTime', it combines the results into one Maybe.+--+-- Uses global Manager.+--+-- Raises an error if the http request fails.+--+-- @since 0.1.11+httpFileSizeAndTime' :: String -> IO (Maybe (Integer, UTCTime))+httpFileSizeAndTime' url = do+  headers <- httpFileHeaders' url+  return $ msizetime headers+  where+    msizetime headers = do+      size <- read . B.unpack <$> lookup hContentLength headers+      date <- lookup hLastModified headers+      time <- httpDateToUTC <$> parseHTTPDate date+      return (size,time)+ -- | Return the HTTP headers for a file -- -- Raises an error if the http request fails.@@ -257,6 +274,7 @@   return $ responseHeaders response  -- | Return the HTTP headers of an http file.+-- -- Global Manager version. -- -- Raises an error if the http request fails.@@ -351,11 +369,7 @@  -- from simple-cmd error' :: String -> a-#if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,9,0)) error' = errorWithoutStackTrace-#else-error' = error-#endif  -- | This +\/+ eats extra slashes. --@@ -366,12 +380,11 @@ -- @since 0.1.9 infixr 5 +/+ (+/+) :: String -> String -> String-"" +/+ s = s-s +/+ "" = s-s +/+ t | last s == '/' = init s +/+ t-        | head t == '/' = s +/+ tail t-s +/+ t = s ++ "/" ++ t-+s +/+ t =+  case (s,t) of+    ("",_) -> t+    (_,"") -> s+    (_,_) -> L.dropWhileEnd (== '/') s ++ '/' : L.dropWhile (== '/') t  #if !MIN_VERSION_base(4,11,0) infixl 1 <&>
test/Spec.hs view
@@ -118,18 +118,18 @@    -- https://github.com/postmanlabs/httpbin/issues/617   describe "httpRedirect" $ do-    it "httpbingo" $ do+    it "httpRedirect" $ do       mgr <- httpManager-      mredir <- httpRedirect mgr "http://httpbingo.org/relative-redirect/1"+      mredir <- httpRedirect mgr "http://httpbin.org/redirect/1"       isJust mredir `shouldBe` True -    it "httpbingo'" $ do-      mredir <- httpRedirect' "http://httpbingo.org/relative-redirect/1"+    it "httpRedirect'" $ do+      mredir <- httpRedirect' "http://httpbin.org/redirect/1"       isJust mredir `shouldBe` True -    it "3 redirs" $ do+    it "2 httpRedirects" $ do       mgr <- httpManager-      redirs <- httpRedirects mgr "http://httpbingo.org/relative-redirect/2"+      redirs <- httpRedirects mgr "http://httpbin.org/redirect/2"       length redirs `shouldBe` 2    describe "isHttpUrl" $ do