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

Safe HaskellNone
LanguageHaskell98

Network.HTTP.Proxy

Description

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

Synopsis

Documentation

type Port = Int Source

data Request Source

Constructors

Request 

Fields

requestMethod :: Method

Request method such as GET.

httpVersion :: HttpVersion

HTTP version such as 1.1.

requestHeaders :: RequestHeaders

A list of header (a pair of key and value) in an HTTP request.

requestPath :: ByteString

The part of the URL before the query part.

queryString :: ByteString

Parsed query string information

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 defaultProxySettings and record syntax to modify individual records. For example:

defaultProxySettings { proxyPort = 3128 }

Constructors

Settings 

Fields

proxyPort :: Int

Port to listen on. Default value: 3100

proxyHost :: HostPreference

Default value: HostIPv4

proxyOnException :: SomeException -> Response

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 (Either Response Request)

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

proxyLogger :: ByteString -> IO ()

A function for logging proxy internal state. Default: 'return ()'.

proxyUpstream :: Maybe UpstreamProxy

Optional upstream proxy.

data UpstreamProxy Source

A http-proxy can be configured to use and upstream proxy by providing the proxy name, the port it listens to and an option username and password for proxy authorisation.

Constructors

UpstreamProxy 

Fields

upstreamHost :: ByteString

The upstream proxy's hostname.

upstreamPort :: Int

The upstream proxy's port number.

upstreamAuth :: Maybe (ByteString, ByteString)

Optional username and password to use with upstream proxy.

runProxy :: Port -> IO () Source

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

runProxySettings :: Settings -> IO () Source

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

runProxySettingsSocket :: Settings -> Socket -> IO () Source

Run a HTTP and HTTPS proxy server with the specified settings but provide it with a Socket to accept connections on. The Socket should have already have had bind and listen called on it so that the proxy can simple accept connections.

defaultProxySettings :: Settings Source

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