1 {-# LANGUAGE OverloadedStrings #-}
2 module FuncTorrent.Network
8 import Prelude hiding (concat)
10 import Data.ByteString (ByteString)
11 import Data.ByteString.Char8 as BC (pack, unpack, concat, intercalate)
12 import Network.HTTP (simpleHTTP, defaultGETRequest_, getResponseBody)
13 import Network.URI (parseURI)
15 -- | Make a query string from a alist of k, v
16 -- TODO: Url encode each argument
17 mkParams :: [(String, ByteString)] -> ByteString
18 mkParams params = BC.intercalate "&" [concat [pack f, "=", s] | (f,s) <- params]
20 httpget :: String -> [(String, ByteString)] -> IO ByteString
21 httpget url args = simpleHTTP (defaultGETRequest_ url') >>= getResponseBody
22 where url' = case parseURI $ unpack $ concat [pack url, "?", qstr] of
24 _ -> error "Bad tracker URL"