packages feed

http-directory 0.1.1 → 0.1.2

raw patch · 4 files changed

+34/−11 lines, 4 filesdep +http-client-tlsPVP ok

version bump matches the API change (PVP)

Dependencies added: http-client-tls

API changes (from Hackage documentation)

+ Network.HTTP.Directory: httpManager :: IO Manager

Files

CHANGELOG.md view
@@ -2,6 +2,11 @@  `http-directory` uses [PVP Versioning](https://pvp.haskell.org). +## 0.1.2+- add httpManager convenient function+- print url when result not 200+- add an example+ ## 0.1.1 - add httpLastModified 
README.md view
@@ -15,4 +15,4 @@ but since http directories are just html pages it can actually be used to list the links (href's) on any html webpage. -See the haddock documentation for usage.+See an [example](https://github.com/juhp/http-directory/blob/master/example/latest-ghc.hs) and the haddock documentation for usage.
http-directory.cabal view
@@ -1,11 +1,10 @@ cabal-version:       1.18 name:                http-directory-version:             0.1.1+version:             0.1.2 synopsis:            http directory listing library description:-            Library for listing http directories of files (links).-            Also it can check the size and modtime of files,-            and for url redirects.+            Library for listing the files (links) in an http directory.+            Also can check the size and modtime of files, and for url redirects. homepage:            https://github.com/juhp/http-directory bug-reports:         https://github.com/juhp/http-directory/issues license:             MIT@@ -18,7 +17,7 @@ extra-doc-files:     README.md                    , CHANGELOG.md tested-with:         GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2,-                     GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.4+                     GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5  source-repository head   type:                git@@ -33,6 +32,7 @@                        bytestring,                        html-conduit,                        http-client,+                       http-client-tls,                        http-date,                        http-types,                        text,
src/Network/HTTP/Directory.hs view
@@ -22,6 +22,7 @@        ( httpDirectory,          httpFileSize,          httpLastModified,+         httpManager,          httpRedirect,          httpRedirects        ) where@@ -37,8 +38,9 @@ import Data.Time.Clock (UTCTime)  import Network.HTTP.Client (hrRedirects, httpLbs, httpNoBody, Manager, method,-                            parseRequest, responseBody, responseHeaders,-                            responseOpenHistory, responseStatus)+                            newManager, parseRequest, responseBody,+                            responseHeaders, responseOpenHistory, responseStatus)+import Network.HTTP.Client.TLS (tlsManagerSettings) import Network.HTTP.Date (httpDateToUTC, parseHTTPDate) import Network.HTTP.Types (hContentLength, hLocation, statusCode) @@ -58,7 +60,9 @@   request <- parseRequest url   response <- httpLbs request mgr   if statusCode (responseStatus response) /= 200-    then error $ show $ responseStatus response+    then do+    putStrLn url+    error $ show $ responseStatus response     else do     let body = responseBody response         doc = parseLBS body@@ -73,7 +77,9 @@   request <- parseRequest url   response <- httpNoBody (request {method = "HEAD"}) mgr   if statusCode (responseStatus response) /= 200-    then error $ show $ responseStatus response+    then do+    putStrLn url+    error $ show $ responseStatus response     else do     let headers = responseHeaders response     return $ read . B.unpack <$> lookup hContentLength headers@@ -81,16 +87,28 @@ -- | Try to get the modification time (Last-Modified field) of an http file -- -- Raises an error if the http request fails.+--+-- @since 0.1.1 httpLastModified :: Manager -> String -> IO (Maybe UTCTime) httpLastModified mgr url = do   request <- parseRequest url   response <- httpNoBody (request {method = "HEAD"}) mgr   if statusCode (responseStatus response) /= 200-    then error $ show $ responseStatus response+    then do+    putStrLn url+    error $ show $ responseStatus response     else do     let headers = responseHeaders response         mdate = lookup "Last-Modified" headers     return $ httpDateToUTC <$> maybe Nothing parseHTTPDate mdate++-- | alias for 'newManager tlsManagerSettings'+-- so one does not need to import http-client etc+--+-- @since 0.1.2+httpManager :: IO Manager+httpManager =+  newManager tlsManagerSettings  -- | Returns the list of http redirects for an url in reverse order -- (ie last redirect is listed first)