Safe Haskell | None |
---|
- data ProxyDest = ProxyDest {
- pdHost :: !ByteString
- pdPort :: !Int
- rawProxyTo :: (MonadBaseControl IO m, MonadIO m) => (RequestHeaders -> m (Either (Application m) ProxyDest)) -> Application m
- waiProxyTo :: (Request -> ResourceT IO WaiProxyResponse) -> (SomeException -> Application) -> Manager -> Application
- defaultOnExc :: SomeException -> Application
- waiProxyToSettings :: (Request -> ResourceT IO WaiProxyResponse) -> WaiProxySettings -> Manager -> Request -> ResourceT IO Response
- data WaiProxyResponse
- data WaiProxySettings
- def :: Default a => a
- wpsOnExc :: WaiProxySettings -> SomeException -> Application
- wpsTimeout :: WaiProxySettings -> Maybe Int
- wpsSetIpHeader :: WaiProxySettings -> SetIpHeader
- wpsProcessBody :: WaiProxySettings -> Response () -> Maybe (Conduit ByteString (ResourceT IO) (Flush Builder))
- data SetIpHeader
- waiToRaw :: Application -> Application IO
Types
Host/port combination to which we want to proxy.
ProxyDest | |
|
Raw
:: (MonadBaseControl IO m, MonadIO m) | |
=> (RequestHeaders -> m (Either (Application m) ProxyDest)) | How to reverse proxy. A |
-> Application m |
Set up a reverse proxy server, which will have a minimal overhead.
This function uses raw sockets, parsing as little of the request as possible. The workflow is:
- Parse the first request headers.
- Ask the supplied function to specify how to reverse proxy.
- Open up a connection to the given host/port.
- Pass all bytes across the wire unchanged.
If you need more control, such as modifying the request or response, use waiProxyTo
.
WAI + http-conduit
:: (Request -> ResourceT IO WaiProxyResponse) | How to reverse proxy. A |
-> (SomeException -> Application) | How to handle exceptions when calling remote server. For a
simple 502 error page, use |
-> Manager | connection manager to utilize |
-> Application |
Creates a WAI Application
which will handle reverse proxies.
Connections to the proxied server will be provided via http-conduit. As
such, all requests and responses will be fully processed in your reverse
proxy. This allows you much more control over the data sent over the wire,
but also incurs overhead. For a lower-overhead approach, consider
rawProxyTo
.
Most likely, the given application should be run with Warp, though in theory other WAI handlers will work as well.
Note: This function will use chunked request bodies for communicating with the proxied server. Not all servers necessarily support chunked request bodies, so please confirm that yours does (Warp, Snap, and Happstack, for example, do).
defaultOnExc :: SomeException -> ApplicationSource
Sends a simple 502 bad gateway error message with the contents of the exception.
waiProxyToSettings :: (Request -> ResourceT IO WaiProxyResponse) -> WaiProxySettings -> Manager -> Request -> ResourceT IO ResponseSource
data WaiProxyResponse Source
The different responses that could be generated by a waiProxyTo
lookup
function.
Since 0.2.0
WPRResponse Response | Respond with the given WAI Response. Since 0.2.0 |
WPRProxyDest ProxyDest | Send to the given destination. Since 0.2.0 |
WPRModifiedRequest Request ProxyDest | Send to the given destination, but use the given modified Request for computing the reverse-proxied request. This can be useful for reverse proxying to a different path than the one specified. By the user. Since 0.2.0 |
Settings
wpsSetIpHeader :: WaiProxySettings -> SetIpHeaderSource
Set the X-Real-IP request header with the client's IP address.
Default: SIHFromSocket
Since 0.2.0
wpsProcessBody :: WaiProxySettings -> Response () -> Maybe (Conduit ByteString (ResourceT IO) (Flush Builder))Source
Post-process the response body returned from the host.
Since 0.2.1
data SetIpHeader Source
How to set the X-Real-IP request header.
Since 0.2.0
SIHNone | Do not set the header |
SIHFromSocket | Set it from the socket's address. |
SIHFromHeader | Set it from either X-Real-IP or X-Forwarded-For, if present |
WAI to Raw
waiToRaw :: Application -> Application IOSource
Convert a WAI application into a raw application, using Warp.