packages feed

http-directory 0.1.2 → 0.1.3

raw patch · 3 files changed

+44/−18 lines, 3 filesdep +cryptonitePVP ok

version bump matches the API change (PVP)

Dependencies added: cryptonite

API changes (from Hackage documentation)

+ Network.HTTP.Directory: httpExists :: Manager -> String -> IO Bool

Files

CHANGELOG.md view
@@ -2,13 +2,16 @@  `http-directory` uses [PVP Versioning](https://pvp.haskell.org). -## 0.1.2+## 0.1.3 (2019-06-04)+- add httpExists++## 0.1.2 (2019-05-07) - add httpManager convenient function - print url when result not 200 - add an example -## 0.1.1+## 0.1.1 (2019-04-14) - add httpLastModified -## 0.1.0+## 0.1.0 (2019-04-11) - initial release with httpDirectory, httpFileSize, and httpRedirect(s)
http-directory.cabal view
@@ -1,10 +1,11 @@ cabal-version:       1.18 name:                http-directory-version:             0.1.2+version:             0.1.3 synopsis:            http directory listing library description:             Library for listing the files (links) in an http directory.-            Also can check the size and modtime of files, and for url redirects.+            Also can 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 license:             MIT@@ -39,7 +40,8 @@                        time,                        xml-conduit   if impl(ghc<8.0)-      Build-depends: semigroups+      build-depends: semigroups,+                     cryptonite < 0.26    ghc-options:         -fwarn-missing-signatures                        -Wall
src/Network/HTTP/Directory.hs view
@@ -6,11 +6,9 @@ @ import Network.HTTP.Directory import qualified Data.Text as T-import Network.HTTP.Client (newManager)-import Network.HTTP.Client.TLS (tlsManagerSettings)  main = do-  mgr <- newManager tlsManagerSettings+  mgr <- httpManager   files <- httpDirectory mgr "https://example.com/some/dir/"   mapM_ T.putStrLn files   httpFileSize mgr (head files) >>= print@@ -20,6 +18,7 @@  module Network.HTTP.Directory        ( httpDirectory,+         httpExists,          httpFileSize,          httpLastModified,          httpManager,@@ -38,11 +37,12 @@ import Data.Time.Clock (UTCTime)  import Network.HTTP.Client (hrRedirects, httpLbs, httpNoBody, Manager, method,-                            newManager, parseRequest, responseBody,-                            responseHeaders, responseOpenHistory, responseStatus)+                            newManager, parseRequest,+                            Request, Response, responseBody, responseHeaders,+                            responseOpenHistory, responseStatus) import Network.HTTP.Client.TLS (tlsManagerSettings) import Network.HTTP.Date (httpDateToUTC, parseHTTPDate)-import Network.HTTP.Types (hContentLength, hLocation, statusCode)+import Network.HTTP.Types (hContentLength, hLocation, methodHead, statusCode)  import Text.HTML.DOM (parseLBS) import Text.XML.Cursor@@ -69,13 +69,20 @@         cursor = fromDocument doc     return $ concatMap (attribute "href") $ cursor $// element "a" +-- | Test if an file (url) exists+--+-- @since 0.1.3+httpExists :: Manager -> String -> IO Bool+httpExists mgr url = do+  response <- httpHead mgr url+  return $ statusCode (responseStatus response) == 200+ -- | Try to get the filesize (Content-Length field) of an http file -- -- Raises an error if the http request fails. httpFileSize :: Manager -> String -> IO (Maybe Integer) httpFileSize mgr url = do-  request <- parseRequest url-  response <- httpNoBody (request {method = "HEAD"}) mgr+  response <- httpHead mgr url   if statusCode (responseStatus response) /= 200     then do     putStrLn url@@ -91,8 +98,7 @@ -- @since 0.1.1 httpLastModified :: Manager -> String -> IO (Maybe UTCTime) httpLastModified mgr url = do-  request <- parseRequest url-  response <- httpNoBody (request {method = "HEAD"}) mgr+  response <- httpHead mgr url   if statusCode (responseStatus response) /= 200     then do     putStrLn url@@ -114,11 +120,26 @@ -- (ie last redirect is listed first) httpRedirects :: Manager -> String -> IO [B.ByteString] httpRedirects mgr url = do-  request <- parseRequest url-  respHist <- responseOpenHistory (request {method = "HEAD"}) mgr+  request <- parseRequestHead url+  respHist <- responseOpenHistory request mgr   return $ reverse $ mapMaybe (lookup hLocation . responseHeaders . snd) $ hrRedirects respHist  -- | Return final redirect for an url httpRedirect :: Manager -> String -> IO (Maybe B.ByteString) httpRedirect mgr url =   listToMaybe <$> httpRedirects mgr url++-- parseRequest with HEAD+--+-- @since 0.1.3+parseRequestHead :: String -> IO Request+parseRequestHead url = do+  request <- parseRequest url+  return $ request {method = methodHead}++-- @since 0.1.3+httpHead :: Manager -> String -> IO (Response ())+httpHead mgr url = do+  request <- parseRequestHead url+  httpNoBody request mgr+