-- | HTTP.hs -- A module for download pages from net. module HTTP ( HTTPError(..), downloadPage ) where import DB import Config import Network.Curl import Control.Concurrent hiding (Chan) import Control.OldException data HTTPError = PageDeleted | SomeError deriving Show downloadPage :: Chan -> URL -> IO (Either HTTPError String) downloadPage chan (URL url) = withCurlDo $ do response <- curlGetResponse_ url (curlOptions chan) :: IO (CurlResponse_ [(String, String)] String) return $ case respStatus response of 200 -> Right $ respBody response 404 -> Left PageDeleted _ -> Left SomeError curlOptions :: Chan -> [CurlOption] curlOptions chan = [ CurlTimeout 7 , CurlReferer (curl chan) , CurlUserAgent "Mozilla/5.0 (X11; U; Linux i686; en-US;\ \rv:1.9.1.2) Gecko/20090804 Shiretoko/3.5.2" , CurlCookie (ccookies chan) ]