processUrl :: String -> IO CurlResult
processUrl url_ = go url_ True
    where go url retry = do
            curl <- initialize
            setopts curl [ CurlURL url
                         , CurlUserAgent userAgent
                         , CurlWriteFunction dummyWriteFunction
                         ]
            perform curl
            code <- getResponseCode curl
            if code == 0 && retry
                then go url False
            else if code `elem` [301, 302, 303]
                then getFinalRedirectTarget url >>= \target ->
                    -- If the server just gave us a redirect to the same URL
                    -- (which they sometimes do as a bot-protection measure),
                    -- report that the URL worked fine.
                    if target == url
                        then return $ CurlResult 200 Nothing
                        else return $ CurlResult code (Just target)
            else return $ CurlResult code Nothing
processUrl :: String -> IO CurlResult
processUrl url_ = go url_ True
    where go url retry = do
            curl <- initialize
            setopts curl [ CurlURL url
                         , CurlUserAgent userAgent
                         , CurlWriteFunction dummyWriteFunction
                         ]
            perform curl
            code <- getResponseCode curl
            if code == 0 && retry
                then go url False
            else if code `elem` [301, 302, 303]
                then getFinalRedirectTarget url >>= \target ->
                    -- If the server just gave us a redirect to the same URL
                    -- (which they sometimes do as a bot-protection measure),
                    -- report that the URL worked fine.
                    if target == url
                        then return $ CurlResult 200 Nothing
                        else return $ CurlResult code (Just target)
            else return $ CurlResult code Nothing
processUrl url_ = go url_ True
    where go url retry = do
            curl <- initialize
            setopts curl [ CurlURL url
                         , CurlUserAgent userAgent
                         , CurlWriteFunction dummyWriteFunction
                         ]
            perform curl
            code <- getResponseCode curl
            if code == 0 && retry
                then go url False
            else if code `elem` [301, 302, 303]
                then getFinalRedirectTarget url >>= \target ->
                    -- If the server just gave us a redirect to the same URL
                    -- (which they sometimes do as a bot-protection measure),
                    -- report that the URL worked fine.
                    if target == url
                        then return $ CurlResult 200 Nothing
                        else return $ CurlResult code (Just target)
            else return $ CurlResult code Nothing