wai-app-file-cgi-3.1.12: File/CGI/Rev Proxy App of WAI

Safe Haskell | None
Language | Haskell2010

Network.Wai.Application.Classic

Contents

- Common
- Files
- Redirect
- CGI
- Reverse Proxy
- Path
- Misc

Description

WAI (Web Application Interface) Application for static files and CGI.

Synopsis

- data ClassicAppSpec = ClassicAppSpec {
  - softwareName :: ByteString
  - statusFileDir :: Path
  }
- defaultClassicAppSpec :: ClassicAppSpec
- data StatusInfo
  - = StatusByteString ByteString
  - | StatusFile Path Integer
  - | StatusNone
- data FileAppSpec = FileAppSpec {
  - indexFile :: Path
  - isHTML :: Path -> Bool
  }
- defaultFileAppSpec :: FileAppSpec
- data FileRoute = FileRoute {
  - fileSrc :: Path
  - fileDst :: Path
  }
- fileApp :: ClassicAppSpec -> FileAppSpec -> FileRoute -> Application
- data RedirectRoute = RedirectRoute {
  - redirectSrc :: Path
  - redirectDst :: Path
  }
- redirectApp :: ClassicAppSpec -> RedirectRoute -> Application
- data CgiAppSpec = CgiAppSpec {
  - indexCgi :: Path
  }
- defaultCgiAppSpec :: CgiAppSpec
- data CgiRoute = CgiRoute {
  - cgiSrc :: Path
  - cgiDst :: Path
  }
- cgiApp :: ClassicAppSpec -> CgiAppSpec -> CgiRoute -> Application
- data RevProxyAppSpec = RevProxyAppSpec {
  - revProxyManager :: Manager
  }
- data RevProxyRoute = RevProxyRoute {
  - revProxySrc :: Path
  - revProxyDst :: Path
  - revProxyDomain :: ByteString
  - revProxyPort :: Int
  }
- revProxyApp :: ClassicAppSpec -> RevProxyAppSpec -> RevProxyRoute -> Application
- fromString :: IsString a => String -> a
- isSuffixOf :: Path -> Path -> Bool
- (</>) :: Path -> Path -> Path
- (<.>) :: Path -> Path -> Path
- hasTrailingPathSeparator :: Path -> Bool
- type Path = ByteString
- pathString :: Path -> String
- (<\>) :: Path -> Path -> Path
- breakAtSeparator :: Path -> (Path, Path)
- hasLeadingPathSeparator :: Path -> Bool
- redirectHeader :: Request -> ResponseHeaders
- hostPort :: Request -> (ByteString, ByteString)

# Common

data ClassicAppSpec Source #

Constructors

ClassicAppSpec |

Fields

- softwareName :: ByteString

  Name specified to Server: in HTTP response.

- statusFileDir :: Path

  A function to get HTTP's GMT Date.

defaultClassicAppSpec :: ClassicAppSpec Source #

Default value for `ClassicAppSpec`. `softwareName` is "Classic". `dater` calls `epochTime` for every request. `statusFileDir` is "/usr/local/share/html/status/".

data StatusInfo Source #

Constructors

StatusByteString ByteString | HTTP status body is created from `ByteString`.
StatusFile Path Integer | HTTP status body is created from `FilePath`.
StatusNone | No HTTP status body.

#### Instances

Instances details

Show StatusInfo Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods showsPrec :: Int -> StatusInfo -> ShowS Source # show :: StatusInfo -> String Source # showList :: [StatusInfo] -> ShowS Source #
Eq StatusInfo Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods (==) :: StatusInfo -> StatusInfo -> Bool Source # (/=) :: StatusInfo -> StatusInfo -> Bool Source #

# Files

data FileAppSpec Source #

Constructors

FileAppSpec |

Fields

- indexFile :: Path

  A file name of an index file.

- isHTML :: Path -> Bool

  Whether this is an HTML or not.

defaultFileAppSpec :: FileAppSpec Source #

Default value for `defaultFileAppSpec`. `indexFile` is "index.html". `isHTML` matches "*.html" and "*.html".

data FileRoute Source #

Constructors

FileRoute |

Fields

- fileSrc :: Path

  Path prefix to be matched to `rawPathInfo`.

- fileDst :: Path

  Path prefix to an actual file system.

#### Instances

Instances details

Show FileRoute Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods showsPrec :: Int -> FileRoute -> ShowS Source # show :: FileRoute -> String Source # showList :: [FileRoute] -> ShowS Source #
Eq FileRoute Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods (==) :: FileRoute -> FileRoute -> Bool Source # (/=) :: FileRoute -> FileRoute -> Bool Source #

fileApp :: ClassicAppSpec -> FileAppSpec -> FileRoute -> Application Source #

Handle GET and HEAD for a static file.

If `pathInfo` ends with '/', `indexFile` is automatically added. In this case, "Acceptable-Language:" is also handled. Suppose `indexFile` is "index.html" and if the value is "ja,en", then "index.html.ja", "index.html.en", and "index.html" are tried to be opened in order.

If `pathInfo` does not end with '/' and a corresponding index file exist, redirection is specified in HTTP response.

Directory contents are NOT automatically listed. To list directory contents, an index file must be created beforehand.

The following HTTP headers are handled: Acceptable-Language:, If-Modified-Since:, Range:, If-Range:, If-Unmodified-Since:.

# Redirect

data RedirectRoute Source #

Constructors

RedirectRoute |

Fields

- redirectSrc :: Path

  Path prefix to be matched to `rawPathInfo`.

- redirectDst :: Path

  Path prefix to an actual file system.

#### Instances

Instances details

Show RedirectRoute Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods showsPrec :: Int -> RedirectRoute -> ShowS Source # show :: RedirectRoute -> String Source # showList :: [RedirectRoute] -> ShowS Source #
Eq RedirectRoute Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods (==) :: RedirectRoute -> RedirectRoute -> Bool Source # (/=) :: RedirectRoute -> RedirectRoute -> Bool Source #

redirectApp :: ClassicAppSpec -> RedirectRoute -> Application Source #

# CGI

data CgiAppSpec Source #

Constructors

CgiAppSpec |

Fields

- indexCgi :: Path

  A file name of the default CGI.

#### Instances

Instances details

Show CgiAppSpec Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods showsPrec :: Int -> CgiAppSpec -> ShowS Source # show :: CgiAppSpec -> String Source # showList :: [CgiAppSpec] -> ShowS Source #
Eq CgiAppSpec Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods (==) :: CgiAppSpec -> CgiAppSpec -> Bool Source # (/=) :: CgiAppSpec -> CgiAppSpec -> Bool Source #

defaultCgiAppSpec :: CgiAppSpec Source #

Default value for `defaultCgiAppSpec`. `indexCgi` is "index.cgi".

data CgiRoute Source #

Constructors

CgiRoute |

Fields

- cgiSrc :: Path

  Path prefix to be matched to `rawPathInfo`.

- cgiDst :: Path

  Path prefix to an actual file system.

#### Instances

Instances details

Show CgiRoute Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods showsPrec :: Int -> CgiRoute -> ShowS Source # show :: CgiRoute -> String Source # showList :: [CgiRoute] -> ShowS Source #
Eq CgiRoute Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods (==) :: CgiRoute -> CgiRoute -> Bool Source # (/=) :: CgiRoute -> CgiRoute -> Bool Source #

cgiApp :: ClassicAppSpec -> CgiAppSpec -> CgiRoute -> Application Source #

Handle GET and POST for CGI.

The program to link this library must ignore SIGCHLD as follows:

      installHandler sigCHLD Ignore Nothing

# Reverse Proxy

data RevProxyAppSpec Source #

Constructors

RevProxyAppSpec |

Fields

- revProxyManager :: Manager

  Connection manager

data RevProxyRoute Source #

Constructors

RevProxyRoute |

Fields

- revProxySrc :: Path

  Path prefix to be matched to `rawPathInfo`.

- revProxyDst :: Path

  Destination path prefix.

- revProxyDomain :: ByteString

  Destination domain name.

- revProxyPort :: Int

  Destination port number.

#### Instances

Instances details

Show RevProxyRoute Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods showsPrec :: Int -> RevProxyRoute -> ShowS Source # show :: RevProxyRoute -> String Source # showList :: [RevProxyRoute] -> ShowS Source #
Eq RevProxyRoute Source # |
Instance details Defined in Network.Wai.Application.Classic.Types Methods (==) :: RevProxyRoute -> RevProxyRoute -> Bool Source # (/=) :: RevProxyRoute -> RevProxyRoute -> Bool Source #

revProxyApp :: ClassicAppSpec -> RevProxyAppSpec -> RevProxyRoute -> Application Source #

Relaying any requests as reverse proxy.

# Path

fromString :: IsString a => String -> a Source #

isSuffixOf :: Path -> Path -> Bool Source #

(</>) :: Path -> Path -> Path Source #

Appending with the file separator.

    >>> "/foo" </> "bar"
    "/foo/bar"
    >>> "/foo/" </> "bar"
    "/foo/bar"
    >>> "/foo" </> "/bar"
    "/foo/bar"
    >>> "/foo/" </> "/bar"
    "/foo/bar"

(<.>) :: Path -> Path -> Path Source #

Adding suffix.

hasTrailingPathSeparator :: Path -> Bool Source #

Checking if the path ends with the path separator.

    >>> hasTrailingPathSeparator "/foo/bar/"
    True
    >>> hasTrailingPathSeparator "/foo/bar"
    False

type Path = ByteString Source #

File path.

pathString :: Path -> String Source #

(<\>) :: Path -> Path -> Path Source #

Removing prefix. The prefix of the second argument is removed from the first argument.

    >>> "foobar" <\> "foo"
    "bar"
    >>> "foo" <\> "foobar"
    ""
    >>> "foobar" <\> "baz"
    "bar"

breakAtSeparator :: Path -> (Path, Path) Source #

Breaking at the first path separator.

    >>> breakAtSeparator "/foo/bar/baz"
    ("","/foo/bar/baz")
    >>> breakAtSeparator "foo/bar/baz"
    ("foo","/bar/baz")
    >>> breakAtSeparator "foo"
    ("foo","")

hasLeadingPathSeparator :: Path -> Bool Source #

Checking if the path ends with the path separator.

    >>> hasLeadingPathSeparator "/foo/bar"
    True
    >>> hasLeadingPathSeparator "foo/bar"
    False

# Misc

redirectHeader :: Request -> ResponseHeaders Source #

hostPort :: Request -> (ByteString, ByteString) Source #