Safe Haskell | None |
---|---|
Language | Haskell2010 |
A library for listing "files" in an http "directory".
import Network.HTTP.Directory
import qualified Data.Text as T
import qualified Data.Text.IO as T
main = do
let url = "https://example.com/some/dir/"
files <- 'httpDirectory'' url
mapM_ T.putStrLn files
let file = url +/+
T.unpack (head files)
'httpFileSize'' file >>= print
'httpLastModified'' file >>= print
The main methods use http-client and most of the primed ones http-conduit.
Synopsis
- httpDirectory :: Manager -> String -> IO [Text]
- httpDirectory' :: String -> IO [Text]
- httpRawDirectory :: Manager -> String -> IO [Text]
- httpRawDirectory' :: String -> IO [Text]
- httpExists :: Manager -> String -> IO Bool
- httpExists' :: String -> IO Bool
- httpFileSize :: Manager -> String -> IO (Maybe Integer)
- httpFileSize' :: String -> IO (Maybe Integer)
- httpLastModified :: Manager -> String -> IO (Maybe UTCTime)
- httpLastModified' :: String -> IO (Maybe UTCTime)
- httpManager :: IO Manager
- httpRedirect :: Manager -> String -> IO (Maybe ByteString)
- httpRedirect' :: String -> IO (Maybe ByteString)
- httpRedirects :: Manager -> String -> IO [ByteString]
- isHttpUrl :: String -> Bool
- trailingSlash :: String -> String
- noTrailingSlash :: Text -> Text
- data Manager
- (+/+) :: String -> String -> String
Documentation
httpDirectory :: Manager -> String -> IO [Text] Source #
List the files (hrefs) in an http directory
It filters out absolute urls & paths, queries, '..', and #
links.
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).
(Before 0.1.4 this was the same as httpRawDirectory)
httpDirectory' :: String -> IO [Text] Source #
Like httpDirectory but uses own Manager
Since: 0.1.4
httpRawDirectory :: Manager -> String -> IO [Text] Source #
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' :: String -> IO [Text] Source #
List all the hrefs in an http directory html file.
Raises an error if the http request fails.
Like httpRawDirectory but uses Network.HTTP.Simple (http-conduit)
Since: 0.1.9
httpExists :: Manager -> String -> IO Bool Source #
Test if an file (url) exists
Since: 0.1.3
httpExists' :: String -> IO Bool Source #
Test if an file (url) exists
Since: 0.1.9
httpFileSize :: Manager -> String -> IO (Maybe Integer) Source #
Try to get the filesize (Content-Length field) of an http file
Raises an error if the http request fails.
httpFileSize' :: String -> IO (Maybe Integer) Source #
Try to get the filesize (Content-Length field) of an http file
Raises an error if the http request fails.
Since: 0.1.9
httpLastModified :: Manager -> String -> IO (Maybe UTCTime) Source #
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' :: String -> IO (Maybe UTCTime) Source #
Try to get the modification time (Last-Modified field) of an http file
Raises an error if the http request fails.
Since: 0.1.9
httpManager :: IO Manager Source #
alias for 'newManager tlsManagerSettings' so one does not need to import http-client etc
Since: 0.1.2
httpRedirect :: Manager -> String -> IO (Maybe ByteString) Source #
Return final redirect for an url
httpRedirect' :: String -> IO (Maybe ByteString) Source #
Like httpRedirect but uses own Manager.
Since: 0.1.4
httpRedirects :: Manager -> String -> IO [ByteString] Source #
Returns the list of http redirects for an url in reverse order (ie last redirect is listed first)
trailingSlash :: String -> String Source #
Make sure an url ends with "/"
trailingSlash "url" == "url/" trailingSlash "url/" == "url/"
Since: 0.1.6
noTrailingSlash :: Text -> Text Source #
Remove all trailing slashes from filename or url
noTrailingSlash "dir/" == "dir" noTrailingSlash "dir//" == "dir"
Since: 0.1.6
Instances
HasHttpManager Manager | |
Defined in Network.HTTP.Client.Types getHttpManager :: Manager -> Manager |