reqcatcher- A local http server to catch the HTTP redirect

Copyright(c) 2016- hiratara
Safe HaskellNone



Web.ReqCatcher starts a local HTTP server which handles just one request and returns that request to the client program. It is useful for CLI program to capture HTTP redirects from outer WEB services by using browser.

  import Web.Authenticate.OAuth

  oauth :: OAuth
  manager :: Manager

  main :: IO ()
  main = do
    c <- newCatcher
    let url = pack (catcherUrl c)
        oauth' = oauth {oauthCallback = Just url}

    credential <- getTemporaryCredential oauth' manager
    putStrLn $ "Access to:\n" ++ (authorizeUrl oauth credential)
    req <- catchRedirect c

    let (Just (Just verifier)) = lookup "oauth_verifier" (queryString req)


data Catcher Source #

Catcher holds the HTTP server instance and wait for a request.

newCatcher :: IO Catcher Source #

Creates the new Catcher instance.

newCatcherWithPort :: Port -> IO Catcher Source #

Creates the new Catcher instance with the specific port.

catchRedirect :: Catcher -> IO Request Source #

Returns the HTTP request cought by Catcher. This function blocks until Catcher catches some requests.