http-proxy-0.0.10: A library for writing HTTP and HTTPS proxies

Safe HaskellSafe-Infered



This module contains a simple HTTP and HTTPS proxy. In the most basic setup, the caller specifies a port and runs it as follows:

 -- Run a HTTPS and HTTPS proxy on port 3128.
 import Network.HTTP.Proxy

 main :: IO ()
 main = runProxy 3128



runProxy :: Port -> IO ()Source

Run a HTTP and HTTPS proxy server on the specified port. This calls runProxySettings with defaultSettings.

runProxySettings :: Settings -> IO ()Source

Run a HTTP and HTTPS proxy server with the specified settings.

data Settings Source

Various proxy server settings. This is purposely kept as an abstract data type so that new settings can be added without breaking backwards compatibility. In order to create a Settings value, use defaultSettings and record syntax to modify individual records. For example:

 defaultSettings { proxyPort = 3128 }




proxyPort :: Int

Port to listen on. Default value: 3100

proxyHost :: HostPreference

Default value: HostIPv4

proxyOnException :: SomeException -> IO ()

What to do with exceptions thrown by either the application or server. Default: ignore server-generated exceptions (see InvalidRequest) and print application-generated applications to stderr.

proxyTimeout :: Int

Timeout value in seconds. Default value: 30

proxyRequestModifier :: Request -> IO Request

A function that allows the the request to be modified before being run. Default: 'return . id'.

defaultSettings :: SettingsSource

The default settings for the Proxy server. See the individual settings for the default value.

data Request

Information on the request sent by the client. This abstracts away the details of the underlying implementation.




requestMethod :: Method
httpVersion :: HttpVersion
rawPathInfo :: ByteString

Extra path information sent by the client. The meaning varies slightly depending on backend; in a standalone server setting, this is most likely all information after the domain name. In a CGI application, this would be the information following the path to the CGI executable itself. Do not modify this raw value- modify pathInfo instead.

rawQueryString :: ByteString

If no query string was specified, this should be empty. This value will include the leading question mark. Do not modify this raw value- modify queryString instead.

serverName :: ByteString

Generally the host requested by the user via the Host request header. Backends are free to provide alternative values as necessary. This value should not be used to construct URLs.

serverPort :: Int

The listening port that the server received this request on. It is possible for a server to listen on a non-numeric port (i.e., Unix named socket), in which case this value will be arbitrary. Like serverName, this value should not be used in URL construction.

requestHeaders :: RequestHeaders
isSecure :: Bool

Was this request made over an SSL connection?

remoteHost :: SockAddr

The client's host information.

pathInfo :: [Text]

Path info in individual pieces- the url without a hostname/port and without a query string, split on forward slashes,

queryString :: Query

Parsed query string information

requestBody :: Source IO ByteString
vault :: Vault

A location for arbitrary data to be shared by applications and middleware.