http-directory 0.1.3 → 0.1.4
raw patch · 3 files changed
+51/−4 lines, 3 filesdep ~http-datePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: http-date
API changes (from Hackage documentation)
+ Network.HTTP.Directory: httpDirectory' :: String -> IO [Text]
+ Network.HTTP.Directory: httpRawDirectory :: Manager -> String -> IO [Text]
+ Network.HTTP.Directory: httpRedirect' :: String -> IO (Maybe ByteString)
Files
- CHANGELOG.md +5/−0
- http-directory.cabal +2/−2
- src/Network/HTTP/Directory.hs +44/−2
CHANGELOG.md view
@@ -2,6 +2,11 @@ `http-directory` uses [PVP Versioning](https://pvp.haskell.org). +## 0.1.4 (2019-06-xx)+- add httpRawDirectory+- httpDirectory now filters out absolutes hrefs and sort links+- add httpDirectory' and httpRedirect' variants with own Manager+ ## 0.1.3 (2019-06-04) - add httpExists
http-directory.cabal view
@@ -1,10 +1,10 @@ cabal-version: 1.18 name: http-directory-version: 0.1.3+version: 0.1.4 synopsis: http directory listing library description: Library for listing the files (links) in an http directory.- Also can check the size, existence, modtime of files,+ It can also check the size, existence, modtime of files, and url redirects. homepage: https://github.com/juhp/http-directory bug-reports: https://github.com/juhp/http-directory/issues
src/Network/HTTP/Directory.hs view
@@ -18,11 +18,14 @@ module Network.HTTP.Directory ( httpDirectory,+ httpDirectory',+ httpRawDirectory, httpExists, httpFileSize, httpLastModified, httpManager, httpRedirect,+ httpRedirect', httpRedirects ) where @@ -32,8 +35,9 @@ #endif import qualified Data.ByteString.Char8 as B+import Data.List (nub) import Data.Maybe-import Data.Text (Text)+import Data.Text (Text, isPrefixOf, pack) import Data.Time.Clock (UTCTime) import Network.HTTP.Client (hrRedirects, httpLbs, httpNoBody, Manager, method,@@ -55,8 +59,39 @@ -- you may need to use 'httpRedirect' to determine -- the actual final url prefix for relative links -- (files).+--+-- (Filters "non-files/subdirs" @since 0.1.4 (before that was just httpRawDirectory) httpDirectory :: Manager -> String -> IO [Text] httpDirectory mgr url = do+ hrefs <- httpRawDirectory mgr url+ return $ nub $ filter (not . or . flist [isHttp, ("/" `isPrefixOf`), (pack "../" ==), ("?" `isPrefixOf`)]) hrefs+ where+ isHttp loc = "http:" `isPrefixOf` loc || "https:" `isPrefixOf` loc++-- picked from swish+flist :: [a->b] -> a -> [b]+flist fs a = map ($ a) fs++-- | Like httpDirectory but uses own Manager+--+-- @since 0.1.4+httpDirectory' :: String -> IO [Text]+httpDirectory' url = do+ mgr <- httpManager+ httpDirectory mgr url++-- | List all the hrefs in an http directory html file.+--+-- Raises an error if the http request fails.+--+-- Note if the directory (webpage) url is redirected to a different path+-- you may need to use 'httpRedirect' to determine+-- the actual final url prefix for relative links+-- (files).+--+-- @since 0.1.4+httpRawDirectory :: Manager -> String -> IO [Text]+httpRawDirectory mgr url = do request <- parseRequest url response <- httpLbs request mgr if statusCode (responseStatus response) /= 200@@ -129,6 +164,14 @@ httpRedirect mgr url = listToMaybe <$> httpRedirects mgr url +-- | Like httpRedirect but uses own Manager.+--+-- @since 0.1.4+httpRedirect' :: String -> IO (Maybe B.ByteString)+httpRedirect' url = do+ mgr <- httpManager+ listToMaybe <$> httpRedirects mgr url+ -- parseRequest with HEAD -- -- @since 0.1.3@@ -142,4 +185,3 @@ httpHead mgr url = do request <- parseRequestHead url httpNoBody request mgr-