http-reverse-proxy: Reverse proxy HTTP requests, either over raw sockets or with WAI

[ bsd3, web ] [ Propose Tags ]

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.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.0.7, 0.1.1, 0.1.1.1, 0.1.1.2, 0.1.1.3, 0.1.1.4, 0.1.1.5, 0.1.1.6, 0.2.0, 0.2.1, 0.2.1.1, 0.3.0, 0.3.0.1, 0.3.1, 0.3.1.1, 0.3.1.2, 0.3.1.3, 0.3.1.4, 0.3.1.5, 0.3.1.6, 0.3.1.7, 0.3.1.8, 0.4.0, 0.4.0.1, 0.4.1.2, 0.4.1.3, 0.4.2, 0.4.3, 0.4.3.1, 0.4.3.2, 0.4.3.3, 0.4.4, 0.4.5, 0.5.0, 0.5.0.1, 0.6.0, 0.6.0.1, 0.6.0.2
Change log ChangeLog.md
Dependencies base (>=4.11 && <5), blaze-builder (>=0.3), bytestring (>=0.9), case-insensitive (>=0.4), conduit (>=1.3), conduit-extra, containers, http-client (>=0.3), http-types (>=0.6), network, resourcet, streaming-commons, text (>=0.11), transformers, unliftio (>=0.2), wai (>=3.0), wai-logger, word8 (>=0.0) [details]
License BSD-3-Clause
Author Michael Snoyman
Maintainer michael@fpcomplete.com
Category Web
Home page https://github.com/fpco/http-reverse-proxy
Source repo head: git clone git://github.com/fpco/http-reverse-proxy.git
Uploaded by MichaelSnoyman at 2023-12-12T09:44:51Z
Distributions Debian:0.6.0, FreeBSD:0.4.2, LTSHaskell:0.6.0.2, NixOS:0.6.0.2, Stackage:0.6.0.2
Reverse Dependencies 7 direct, 5 indirect [details]
Downloads 59614 total (155 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-12-12 [all 1 reports]

Readme for http-reverse-proxy-0.6.0.2

[back to package description]

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.