http-reverse-proxy

Reverse proxy HTTP requests, either over raw sockets or with WAI

https://github.com/fpco/http-reverse-proxy

LTS Haskell 23.1:0.6.1.0
Stackage Nightly 2024-12-21:0.6.1.0
Latest on Hackage:0.6.1.0

See all snapshots http-reverse-proxy appears in

BSD-3-Clause licensed by Michael Snoyman
Maintained by [email protected]
This version can be pinned in stack with:http-reverse-proxy-0.6.1.0@sha256:5bc151ed0c22e8493a7bb5e6e1a5de51fff0450f47733e9bc5044aaafdf7dac6,2542

Module documentation for 0.6.1.0

http-reverse-proxy

Provides a simple means of reverse-proxying HTTP requests. The raw approach uses the same technique as leveraged by keter, whereas the WAI approach performs full request/response parsing via WAI and http-conduit.

Raw example

The following sets up raw reverse proxying from local port 3000 to www.example.com, port 80.

{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.ReverseProxy
import Data.Conduit.Network

main :: IO ()
main = runTCPServer (serverSettings 3000 "*") $ \appData ->
    rawProxyTo
        (\_headers -> return $ Right $ ProxyDest "www.example.com" 80)
        appData

HTTPS example to proxy bing.com

The following example sets up reverse proxying froming to www.bing.com from localhost port 3000:

import Network.HTTP.Client.TLS
import Network.HTTP.ReverseProxy
import Network.Wai
import Network.Wai.Handler.Warp (run)

main :: IO ()
main = bingExample >>= run 3000

bingExample :: IO Application
bingExample = do
  manager <- newTlsManager
  pure $
    waiProxyToSettings
      ( \request ->
          return $
            WPRModifiedRequestSecure
              ( request
                  { requestHeaders = [("Host", "www.bing.com")]
                  }
              )
              (ProxyDest "www.bing.com" 443)
      )
      defaultWaiProxySettings {wpsLogRequest = print}
      manager

After running it, you can visit http://localhost:3000 to visit the search engine’s page.

Changes

0.6.1.0

  • Add the wpsModifyResponseHeaders option to WaiProxySettings to tweak response headers before they are returned upstream. #48

0.6.0.3

  • Fix a regression introduced in 0.6.0.2: wrong ‘Content-Length’ header is preserved for responses with encoded content. #47

0.6.0.2

  • Fix docker registry reverse proxying by preserving the ‘Content-Length’ response header to HTTP/2 and HEAD requests. #45

0.6.0.1

  • Introduce a “semi cached body” to let the beginning of a request body be retried #34
  • Add wpsLogRequest function which provides the ability to log the constructed Request.

0.6.0

  • Switch over to unliftio and conduit 1.3
  • Drop dependency on data-default-class, drop Default instances

0.5.0.1

  • Support http-conduit 2.3 in test suite #26

0.5.0

  • update wpsProcessBody to accept response’s initial request

0.4.5

  • add Eq, Ord, Show, Read instances to ProxyDest

0.4.4

  • add rawTcpProxyTo which can handle proxying connections without http headers #21

0.4.3.3

  • fixReqHeaders may create weird x-real-ip header #19

0.4.3.2

  • Minor doc cleanup

0.4.3.1

  • Use CPP so we can work with http-client pre and post 0.5 #17

0.4.3

  • Allow proxying to HTTPS servers. #15

0.4.2

  • Add configurable timeouts #8

0.4.1.3

  • Include README.md and ChangeLog.md