blob: 18764105559449def24f0a4574057cd3e366c649 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
module HTTP
( getPage
) where
import Control.Exception (SomeException, try)
import Control.Arrow (left)
import Control.Applicative ((<$>))
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Network.HTTP (simpleHTTP, getRequest, getResponseBody)
import Network.HTTP.Headers (insertHeader, HeaderName(HdrAcceptLanguage))
import Model.URL
import Codec.Binary.UTF8.String (decodeString)
getPage :: URL -> IO (Either Text Text)
getPage url =
left (T.pack . show) <$> (try (unsafeGetPage url) :: IO (Either SomeException Text))
unsafeGetPage :: URL -> IO Text
unsafeGetPage url = simpleHTTP (insertHeader HdrAcceptLanguage "en" $ getRequest (T.unpack url)) >>= (\x -> T.pack . decodeString <$> getResponseBody x)
|