snap-core-1.0.5.1: Snap: A Haskell Web Framework (core interfaces and types)

Safe Haskell | None
Language | Haskell2010

Snap.Util.Proxy

Description

This module provides facilities for patching incoming `Requests` to correct the value of `rqClientAddr` if the snap server is running behind a proxy.

Example usage:

    m :: Snap ()
    m = undefined  -- code goes here

    applicationHandler :: Snap ()
    applicationHandler = behindProxy X_Forwarded_For m

Synopsis

- data ProxyType
  - = NoProxy
  - | X_Forwarded_For
- behindProxy :: MonadSnap m => ProxyType -> m a -> m a

# Documentation

data ProxyType Source #

What kind of proxy is this? Affects which headers `behindProxy` pulls the original remote address from.

Currently only proxy servers that send `X-Forwarded-For` or `Forwarded-For` are supported.

Constructors

NoProxy | no proxy, leave the request alone
X_Forwarded_For | Use the `Forwarded-For` or `X-Forwarded-For` header

#### Instances

Instances details

Read ProxyType Source # |
Instance details Defined in Snap.Util.Proxy Methods readsPrec :: Int -> ReadS ProxyType Source # readList :: ReadS [ProxyType] Source # readPrec :: ReadPrec ProxyType Source # readListPrec :: ReadPrec [ProxyType] Source #
Show ProxyType Source # |
Instance details Defined in Snap.Util.Proxy Methods showsPrec :: Int -> ProxyType -> ShowS Source # show :: ProxyType -> String Source # showList :: [ProxyType] -> ShowS Source #
Eq ProxyType Source # |
Instance details Defined in Snap.Util.Proxy Methods (==) :: ProxyType -> ProxyType -> Bool Source # (/=) :: ProxyType -> ProxyType -> Bool Source #
Ord ProxyType Source # |
Instance details Defined in Snap.Util.Proxy Methods compare :: ProxyType -> ProxyType -> Ordering Source # (<) :: ProxyType -> ProxyType -> Bool Source # (<=) :: ProxyType -> ProxyType -> Bool Source # (>) :: ProxyType -> ProxyType -> Bool Source # (>=) :: ProxyType -> ProxyType -> Bool Source # max :: ProxyType -> ProxyType -> ProxyType Source # min :: ProxyType -> ProxyType -> ProxyType Source #

behindProxy :: MonadSnap m => ProxyType -> m a -> m a Source #

Rewrite `rqClientAddr` if we're behind a proxy.

Example:

    ghci> :set -XOverloadedStrings
    ghci> import qualified Data.Map as M
    ghci> import qualified Snap.Test as T
    ghci> let r = T.get "/foo" M.empty >> T.addHeader "X-Forwarded-For" "1.2.3.4"
    ghci> let h = getsRequest rqClientAddr >>= writeBS)
    ghci> T.runHandler r h
    HTTP/1.1 200 OK
    server: Snap/test
    date: Fri, 08 Aug 2014 14:32:29 GMT

    127.0.0.1
    ghci> T.runHandler r (behindProxy X_Forwarded_For h)
    HTTP/1.1 200 OK
    server: Snap/test
    date: Fri, 08 Aug 2014 14:33:02 GMT

    1.2.3.4