In this simple case I was testing a service that performs geoip redirection to confirm if IP addresses for a known region were being redirected to the expected location. They were not.
I was using a fairly recent stackage nightly build (2015-07-05) but the newest
version of http-conduit it had was 2.1.5
whereas the newest version (at the
time of writing) is 2.1.7
which deprecates the withManager
function I used.
{-# LANGUAGE OverloadedStrings #-}
module Lib
( examinewhere
)
import Network (withSocketsDo)
import Network.HTTP.Conduit
import Network.HTTP.Types
import Control.Monad
import qualified Data.ByteString as B
import Addresses (addresses)
import qualified Data.HashMap.Strict as M
= [
getHeaders fwd "X-Forwarded-proto", "https"),
("X-Forwarded-for", fwd),
("Host", "www.myspace.com") ]
(
= take 100 addresses
addresses'
= "https://www.myspace.com"
expectedLocation
getResponseHeaders :: B.ByteString -> IO ResponseHeaders
= withSocketsDo $ do
getResponseHeaders fwd <- parseUrl "http://<some_ip>"
request' let request = request' { requestHeaders = getHeaders fwd
= 0
, redirectCount = \_ _ _ -> Nothing}
, checkStatus $ \manager -> do
withManager <- http request manager
response return $ responseHeaders response
examine :: IO ()
= do
examine <- forM addresses' getMatchingness
results filter doesNotMatch results) $ \x -> print x
forM_ (where
= not b
doesNotMatch (_, _, b) = M.lookupDefault "" "Location"
convHeaders = do
getMatchingness url <- getResponseHeaders url
headers let location = convHeaders $ M.fromList headers
B.putStrLn urlreturn (url, location, location == expectedLocation)