reqcatcher-0.1.0.0: A local http server to catch the HTTP redirect

Copyright(c) 2016- hiratara
LicenseBSD-style
Maintainerhiratara@cpan.org
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Web.ReqCatcher

Description

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)
    ...

Synopsis

Documentation

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.