Last active
May 7, 2022 12:28
-
-
Save andrevdm/0bdef665fb5d21395935630f8fd82f68 to your computer and use it in GitHub Desktop.
Haskell reverse proxy using Network.HTTP.ReverseProxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Protolude | |
import qualified Network.HTTP.ReverseProxy as Rp | |
import qualified Network.Wai as W | |
import qualified Network.Wai.Handler.Warp as Wrp | |
import qualified Network.HTTP.Client as HC | |
testProxy :: IO () | |
testProxy = | |
Wrp.run 3000 =<< revProxyApp | |
where | |
revProxyApp = do | |
mgr <- HC.newManager HC.defaultManagerSettings | |
pure $ Rp.waiProxyTo handler Rp.defaultOnExc mgr | |
--pure $ Rp.WPRModifiedRequest (req {W.rawPathInfo = "/"}) (Rp.ProxyDest "eu.httpbin.org" 80) | |
handler :: W.Request -> IO Rp.WaiProxyResponse | |
handler req = do | |
print req | |
pure . Rp.WPRProxyDest $ Rp.ProxyDest "eu.httpbin.org" 80 | |
-- Rp.rawProxyTo | |
-- (\headers -> do | |
-- print headers | |
-- pure . Right $ Rp.ProxyDest "eu.httpbin.org" 80) | |
-- appData |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment