{-|
/DEPRECATED/: Use the HTTP package instead:
> import Network.HTTP
> openURL x = getResponseBody =<< simpleHTTP (getRequest x)
This module simply downloads a page off the internet. It is very restricted,
and it not intended for proper use.
The original version was by Alistair Bayley, with additional help from
Daniel McAllansmith. It is taken from the Haskell-Cafe mailing list
\"Simple HTTP lib for Windows?\", 18 Jan 2007.
<http://thread.gmane.org/gmane.comp.lang.haskell.cafe/18443/>
-}
module Text.HTML.Download(openURL, openItem) where
import System.IO
import System.IO.Unsafe
import Network
import Data.List
{-# DEPRECATED openItem, openURL "Use package HTTP, module Network.HTTP, getResponseBody =<< simpleHTTP (getRequest url)" #-}-- | This function opens a URL on the internet.-- Any @http:\/\/@ prefix is ignored.---- > openURL "www.haskell.org/haskellwiki/Haskell"---- Known Limitations:---- * Only HTTP on port 80---- * Outputs the HTTP Headers as well---- * Does not work with all servers---- It is hoped that a more reliable version of this function will be-- placed in a new HTTP library at some point!openURL :: String -> IOStringopenURLurl | "http://"`isPrefixOf`url = openURL (drop7url)
openURLurl = clientserver80 (if nullpath then "/" else path)
where (server,path) = break (=='/') urlclient :: [Char] -> PortNumber -> [Char] -> IOStringclientserverportpage = withSocketsDo$ do
hndl <- connectToserver (PortNumberport)
let outx = hPutStrLnhndl (x++"\r")
hSetBufferinghndlNoBufferingout$"GET "++page++" HTTP/1.1"out$"Host: "++server++""out$"Connection: close"out""out""readResponsehndlreadResponse :: Handle -> IOStringreadResponsehndl = do
closed <- hIsClosedhndleof <- hIsEOFhndl
if closed||eof
then return []
else do
c <- hGetCharhndlcs <- unsafeInterleaveIO$readResponsehndlreturn (c:cs)
-- | Open a URL (if it starts with @http:\/\/@) or a file otherwiseopenItem :: String -> IOStringopenItemx | "http://"`isPrefixOf`x = openURLx
| otherwise = readFilex