forked from erikd/http-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename proxyRequestModifier field to proxyHttpRequestModifier
This helps remind users that only HTTP requests can be modified.
- Loading branch information
Showing
3 changed files
with
23 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
import Network.HTTP.Proxy | ||
import Network.HTTP.Proxy (ProxySettings (..), Request (..)) | ||
import qualified Network.HTTP.Proxy as Proxy | ||
|
||
main :: IO () | ||
main = runProxySettings $ defaultProxySettings | ||
{ proxyPort = 31081 | ||
, proxyRequestModifier = Just secureGoogle | ||
} | ||
main = | ||
Proxy.runProxySettings $ | ||
Proxy.defaultProxySettings | ||
{ proxyPort = 31081 | ||
, proxyHttpRequestModifier = Just secureGoogle | ||
} | ||
|
||
-- We can modify the request so that instead of going to unsecured Google | ||
-- search page, people get redirected to the encrypted version. | ||
-- Modifying the request like this is only possible for unencrypted HTTP connections | ||
-- by my be useful for eg redirecting HTTP to HTTPS. | ||
-- HTTPS cnnections cannot be modified like this because the for HTTPS connections | ||
-- even the request itself is encrypted. | ||
|
||
secureGoogle :: Request -> IO Request | ||
secureGoogle req | ||
| requestHost req == "www.google.com" = | ||
return $ req | ||
{ requestHost = "encrypted.google.com" | ||
, requestPort = 443 | ||
| "www.google.com" `BS.isInfixOf` requestPath req | ||
&& not ("https" `BS.isprefixOf` requestPath req = | ||
pure $ req | ||
{ requestPath = "encrypted.google.com" | ||
} | ||
|
||
| otherwise = return req | ||
| otherwise = pure req |
This file contains 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