cgi-3001.5.1.0: A library for writing CGI programs

Copyright | (c) The University of Glasgow 2001 (c) Bjorn Bringert 2004-2006 (c) Ian Lynagh 2005 (c) Jeremy Shaw 2005
License | BSD-style
Maintainer | John Chee <cheecheeo@gmail.com>
Stability | experimental
Portability | non-portable (uses Control.Monad.State)
Safe Haskell | None
Language | Haskell2010

Network.CGI

Contents

- CGI monad
- Error handling
- Logging
- Output
- Error pages
- Input
- Environment
- Request information
- Program and request URI
- Content negotiation
- Content type
- Cookies
- URL encoding

Description

Simple Library for writing CGI programs. See https://web.archive.org/web/20100109233524/http://hoohoo.ncsa.illinois.edu/cgi/interface.html for the CGI specification.

This version of the library is for systems with version 2.0 or greater of the network package. This includes GHC 6.6 and later. For older systems, see http://www.cs.chalmers.se/~bringert/darcs/cgi-compat/doc/

Based on the original Haskell binding for CGI:

Original Version by Erik Meijer mailto:erik@cs.ruu.nl. Further hacked on by Sven Panne mailto:sven.panne@aedion.de. Further hacking by Andy Gill mailto:andy@galconn.com. A new, hopefully more flexible, interface and support for file uploads by Bjorn Bringert mailto:bjorn@bringert.net.

Here is a simple example, including error handling (not that there is much that can go wrong with Hello World):

    import Network.CGI

    cgiMain :: CGI CGIResult
    cgiMain = output "Hello World!"

    main :: IO ()
    main = runCGI (handleErrors cgiMain)

Synopsis

- class Monad m => MonadCGI (m :: Type -> Type)
- data CGIT (m :: Type -> Type) a
- data CGIResult
- type CGI a = CGIT IO a
- class Monad m => MonadIO (m :: Type -> Type)
- liftIO :: MonadIO m => IO a -> m a
- runCGI :: MonadIO m => CGIT m CGIResult -> m ()
- throwCGI :: MonadThrow m => SomeException -> m a
- catchCGI :: MonadCatch m => m a -> (SomeException -> m a) -> m a
- tryCGI :: MonadCatch m => m a -> m (Either SomeException a)
- handleExceptionCGI :: MonadCatch m => m a -> (SomeException -> m a) -> m a
- handleErrors :: (MonadCGI m, MonadCatch m, MonadIO m) => m CGIResult -> m CGIResult
- logCGI :: MonadIO m => String -> m ()
- output :: MonadCGI m => String -> m CGIResult
- outputFPS :: MonadCGI m => ByteString -> m CGIResult
- outputNothing :: MonadCGI m => m CGIResult
- redirect :: MonadCGI m => String -> m CGIResult
- setHeader :: MonadCGI m => String -> String -> m ()
- setStatus :: MonadCGI m => Int -> String -> m ()
- outputError :: (MonadCGI m, MonadIO m) => Int -> String -> [String] -> m CGIResult
- outputException :: (MonadCGI m, MonadIO m) => SomeException -> m CGIResult
- outputNotFound :: (MonadIO m, MonadCGI m) => String -> m CGIResult
- outputMethodNotAllowed :: (MonadIO m, MonadCGI m) => [String] -> m CGIResult
- outputInternalServerError :: (MonadIO m, MonadCGI m) => [String] -> m CGIResult
- getInput :: MonadCGI m => String -> m (Maybe String)
- getInputFPS :: MonadCGI m => String -> m (Maybe ByteString)
- readInput :: (Read a, MonadCGI m) => String -> m (Maybe a)
- getBody :: MonadCGI m => m String
- getBodyFPS :: MonadCGI m => m ByteString
- getInputs :: MonadCGI m => m [(String, String)]
- getInputsFPS :: MonadCGI m => m [(String, ByteString)]
- getInputNames :: MonadCGI m => m [String]
- getMultiInput :: MonadCGI m => String -> m [String]
- getMultiInputFPS :: MonadCGI m => String -> m [ByteString]
- getInputFilename :: MonadCGI m => String -> m (Maybe String)
- getInputContentType :: MonadCGI m => String -> m (Maybe String)
- getVar :: MonadCGI m => String -> m (Maybe String)
- getVarWithDefault :: MonadCGI m => String -> String -> m String
- getVars :: MonadCGI m => m [(String, String)]
- serverName :: MonadCGI m => m String
- serverPort :: MonadCGI m => m Int
- requestMethod :: MonadCGI m => m String
- pathInfo :: MonadCGI m => m String
- pathTranslated :: MonadCGI m => m String
- scriptName :: MonadCGI m => m String
- queryString :: MonadCGI m => m String
- remoteHost :: MonadCGI m => m (Maybe String)
- remoteAddr :: MonadCGI m => m String
- authType :: MonadCGI m => m (Maybe String)
- remoteUser :: MonadCGI m => m (Maybe String)
- requestContentType :: MonadCGI m => m (Maybe String)
- requestContentLength :: MonadCGI m => m (Maybe Int)
- requestHeader :: MonadCGI m => String -> m (Maybe String)
- progURI :: MonadCGI m => m URI
- queryURI :: MonadCGI m => m URI
- requestURI :: MonadCGI m => m URI
- class Eq a => Acceptable a
- data Accept a
- newtype Charset = Charset String
- newtype ContentEncoding = ContentEncoding String
- newtype Language = Language String
- requestAccept :: MonadCGI m => m (Maybe (Accept ContentType))
- requestAcceptCharset :: MonadCGI m => m (Maybe (Accept Charset))
- requestAcceptEncoding :: MonadCGI m => m (Maybe (Accept ContentEncoding))
- requestAcceptLanguage :: MonadCGI m => m (Maybe (Accept Language))
- negotiate :: Acceptable a => [a] -> Maybe (Accept a) -> [a]
- data ContentType = ContentType {
  - ctType :: String
  - ctSubtype :: String
  - ctParameters :: [(String, String)]
  }
- showContentType :: ContentType -> String
- parseContentType :: MonadFail m => String -> m ContentType
- data Cookie = Cookie {
  - cookieName :: String
  - cookieValue :: String
  - cookieExpires :: Maybe UTCTime
  - cookieDomain :: Maybe String
  - cookiePath :: Maybe String
  - cookieSecure :: Bool
  - cookieHttpOnly :: Bool
  }
- newCookie :: String -> String -> Cookie
- getCookie :: MonadCGI m => String -> m (Maybe String)
- readCookie :: (Read a, MonadCGI m) => String -> m (Maybe a)
- setCookie :: MonadCGI m => Cookie -> m ()
- deleteCookie :: MonadCGI m => Cookie -> m ()
- formEncode :: [(String, String)] -> String
- urlEncode :: String -> String
- formDecode :: String -> [(String, String)]
- urlDecode :: String -> String

# CGI monad

class Monad m => MonadCGI (m :: Type -> Type) Source #

The class of CGI monads. Most CGI actions can be run in any monad which is an instance of this class, which means that you can use your own monad transformers to add extra functionality.

Minimal complete definition

cgiAddHeader, cgiGet

#### Instances

Instances details

Monad m => MonadCGI (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods cgiAddHeader :: HeaderName -> String -> CGIT m () Source # cgiGet :: (CGIRequest -> a) -> CGIT m a Source #

data CGIT (m :: Type -> Type) a Source #

The CGIT monad transformer.

#### Instances

Instances details

MonadTrans CGIT Source # |
Instance details Defined in Network.CGI.Monad Methods lift :: Monad m => m a -> CGIT m a Source #
MonadCatch m => MonadError SomeException (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods throwError :: SomeException -> CGIT m a Source # catchError :: CGIT m a -> (SomeException -> CGIT m a) -> CGIT m a Source #
MonadIO m => MonadIO (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods liftIO :: IO a -> CGIT m a Source #
Monad m => MonadCGI (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods cgiAddHeader :: HeaderName -> String -> CGIT m () Source # cgiGet :: (CGIRequest -> a) -> CGIT m a Source #
MonadCatch m => MonadCatch (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods catch :: (HasCallStack, Exception e) => CGIT m a -> (e -> CGIT m a) -> CGIT m a Source #
MonadMask m => MonadMask (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods mask :: HasCallStack => ((forall a. CGIT m a -> CGIT m a) -> CGIT m b) -> CGIT m b Source # uninterruptibleMask :: HasCallStack => ((forall a. CGIT m a -> CGIT m a) -> CGIT m b) -> CGIT m b Source # generalBracket :: HasCallStack => CGIT m a -> (a -> ExitCase b -> CGIT m c) -> (a -> CGIT m b) -> CGIT m (b, c) Source #
MonadThrow m => MonadThrow (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods throwM :: (HasCallStack, Exception e) => e -> CGIT m a Source #
Applicative m => Applicative (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods pure :: a -> CGIT m a Source # (<*>) :: CGIT m (a -> b) -> CGIT m a -> CGIT m b Source # liftA2 :: (a -> b -> c) -> CGIT m a -> CGIT m b -> CGIT m c Source # (*>) :: CGIT m a -> CGIT m b -> CGIT m b Source # (<*) :: CGIT m a -> CGIT m b -> CGIT m a Source #
Functor m => Functor (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods fmap :: (a -> b) -> CGIT m a -> CGIT m b Source # (<$) :: a -> CGIT m b -> CGIT m a Source #
Monad m => Monad (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods (>>=) :: CGIT m a -> (a -> CGIT m b) -> CGIT m b Source # (>>) :: CGIT m a -> CGIT m b -> CGIT m b Source # return :: a -> CGIT m a Source #
MonadFail m => MonadFail (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods fail :: String -> CGIT m a Source #

data CGIResult Source #

The result of a CGI program.

#### Instances

Instances details

Read CGIResult Source # |
Instance details Defined in Network.CGI.Protocol Methods readsPrec :: Int -> ReadS CGIResult Source # readList :: ReadS [CGIResult] Source # readPrec :: ReadPrec CGIResult Source # readListPrec :: ReadPrec [CGIResult] Source #
Show CGIResult Source # |
Instance details Defined in Network.CGI.Protocol Methods showsPrec :: Int -> CGIResult -> ShowS Source # show :: CGIResult -> String Source # showList :: [CGIResult] -> ShowS Source #
Eq CGIResult Source # |
Instance details Defined in Network.CGI.Protocol Methods (==) :: CGIResult -> CGIResult -> Bool Source # (/=) :: CGIResult -> CGIResult -> Bool Source #
Ord CGIResult Source # |

Instance details

Defined in Network.CGI.Protocol

Methods

compare :: CGIResult -> CGIResult -> Ordering Source #

(<) :: CGIResult -> CGIResult -> Bool Source #

(<=) :: CGIResult -> CGIResult -> Bool Source #

(>) :: CGIResult -> CGIResult -> Bool Source #

(>=) :: CGIResult -> CGIResult -> Bool Source #

max :: CGIResult -> CGIResult -> CGIResult Source #

min :: CGIResult -> CGIResult -> CGIResult Source #

type CGI a = CGIT IO a Source #

A simple CGI monad with just IO.

class Monad m => MonadIO (m :: Type -> Type) Source #

Monads in which `IO` computations may be embedded. Any monad built by applying a sequence of monad transformers to the `IO` monad will be an instance of this class.

Instances should satisfy the following laws, which state that `liftIO` is a transformer of monads:

-     liftIO . return = return

-     liftIO (m >>= f) = liftIO m >>= (liftIO . f)

Minimal complete definition

liftIO

#### Instances

Instances details

MonadIO IO | Since: base-4.9.0.0
Instance details Defined in Control.Monad.IO.Class Methods liftIO :: IO a -> IO a Source #
MonadIO m => MonadIO (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods liftIO :: IO a -> CGIT m a Source #
MonadIO m => MonadIO (CatchT m) |
Instance details Defined in Control.Monad.Catch.Pure Methods liftIO :: IO a -> CatchT m a Source #
MonadIO m => MonadIO (ReaderT r m) |
Instance details Defined in Control.Monad.Trans.Reader Methods liftIO :: IO a -> ReaderT r m a Source #
(Monoid w, MonadIO m) => MonadIO (WriterT w m) |
Instance details Defined in Control.Monad.Trans.Writer.Lazy Methods liftIO :: IO a -> WriterT w m a Source #
MonadIO m => MonadIO (ParsecT s u m) |
Instance details Defined in Text.Parsec.Prim Methods liftIO :: IO a -> ParsecT s u m a Source #
MonadIO m => MonadIO (ContT r m) |
Instance details Defined in Control.Monad.Trans.Cont Methods liftIO :: IO a -> ContT r m a Source #

liftIO :: MonadIO m => IO a -> m a Source #

Lift a computation from the `IO` monad. This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations (i.e. `IO` is the base monad for the stack).

### Example

Expand

    import Control.Monad.Trans.State -- from the "transformers" library

    printState :: Show s => StateT s IO ()
    printState = do
      state <- get
      liftIO $ print state

Had we omitted ``liftIO``, we would have ended up with this error:

    • Couldn't match type ‘IO’ with ‘StateT s IO’
     Expected type: StateT s IO ()
       Actual type: IO ()

The important part here is the mismatch between `StateT s IO ()` and ``IO` ()`.

Luckily, we know of a function that takes an ``IO` a` and returns an `(m a)`: ``liftIO``, enabling us to run the program and see the expected results:

    > evalStateT printState "hello"
    "hello"

    > evalStateT printState 3
    3

runCGI :: MonadIO m => CGIT m CGIResult -> m () Source #

Run a CGI action. Typically called by the main function. Reads input from stdin and writes to stdout. Gets CGI environment variables from the program environment.

# Error handling

throwCGI :: MonadThrow m => SomeException -> m a Source #

Deprecated: Use Control.Monad.Catch.throwM instead.

Deprecated alias for `throwM`. Please use `throwM` instead.

catchCGI :: MonadCatch m => m a -> (SomeException -> m a) -> m a Source #

Deprecated: Use Control.Monad.Catch.catch instead.

Deprecated alias for `catch`. Please use `catch` instead.

tryCGI :: MonadCatch m => m a -> m (Either SomeException a) Source #

Deprecated: Use Control.Monad.Catch.try instead.

Deprecated alias for `try`. Please use `try` instead.

handleExceptionCGI :: MonadCatch m => m a -> (SomeException -> m a) -> m a Source #

Deprecated: Use Control.Monad.Catch.catch instead.

Deprecated alias for `catch`. Please use `catch` instead.

handleErrors :: (MonadCGI m, MonadCatch m, MonadIO m) => m CGIResult -> m CGIResult Source #

Catches any exception thrown by the given CGI action, returns an error page with a 500 Internal Server Error, showing the exception information, and logs the error.

Typical usage:

    cgiMain :: CGI CGIResult
    cgiMain = ...

    main :: IO ()
    main = runCGI (handleErrors cgiMain)

# Logging

logCGI :: MonadIO m => String -> m () Source #

Logs some message using the server's logging facility. FIXME: does this have to be more general to support FastCGI etc? Maybe we should store log messages in the CGIState?

# Output

output Source #

Arguments

:: MonadCGI m |
=> String | The string to output.
-> m CGIResult |

Output a `String`. The output is assumed to be text/html, encoded using ISO-8859-1. To change this, set the Content-type header using `setHeader`.

outputFPS Source #

Arguments

:: MonadCGI m |
=> ByteString | The string to output.
-> m CGIResult |

Output a `ByteString`. The output is assumed to be text/html, encoded using ISO-8859-1. To change this, set the Content-type header using `setHeader`.

outputNothing :: MonadCGI m => m CGIResult Source #

Do not output anything (except headers).

redirect Source #

Arguments

:: MonadCGI m |
=> String | A URL to redirect to.
-> m CGIResult |

Redirect to some location.

setHeader Source #

Arguments

:: MonadCGI m |
=> String | Header name.
-> String | Header value.
-> m () |

Add a response header. Example:

    setHeader "Content-type" "text/plain"

setStatus Source #

Arguments

:: MonadCGI m |
=> Int | HTTP status code, e.g. `404`
-> String | HTTP status message, e.g. `"Not Found"`
-> m () |

Set the HTTP response status.

# Error pages

outputError Source #

Arguments

:: (MonadCGI m, MonadIO m) |
=> Int | HTTP Status code
-> String | Status message
-> [String] | Error information
-> m CGIResult |

Output an error page to the user, with the given HTTP status code in the response. Also logs the error information using `logCGI`.

outputException :: (MonadCGI m, MonadIO m) => SomeException -> m CGIResult Source #

Output a 500 Internal Server Error with information from an `Exception`.

outputNotFound Source #

Arguments

:: (MonadIO m, MonadCGI m) |
=> String | The name of the requested resource.
-> m CGIResult |

Use `outputError` to output and log a 404 Not Found error.

outputMethodNotAllowed Source #

Arguments

:: (MonadIO m, MonadCGI m) |
=> [String] | The allowed methods.
-> m CGIResult |

Use `outputError` to output and log a 405 Method Not Allowed error.

outputInternalServerError Source #

Arguments

:: (MonadIO m, MonadCGI m) |
=> [String] | Error information.
-> m CGIResult |

Use `outputError` to output and log a 500 Internal Server Error.

# Input

getInput Source #

Arguments

:: MonadCGI m |
=> String | The name of the variable.
-> m (Maybe String) | The value of the variable, or Nothing, if it was not set.

Get the value of an input variable, for example from a form. If the variable has multiple values, the first one is returned. Example:

    query <- getInput "query"

getInputFPS Source #

Arguments

:: MonadCGI m |
=> String | The name of the variable.
-> m (Maybe ByteString) | The value of the variable, or Nothing, if it was not set.

Like `getInput`, but returns a `ByteString`.

readInput Source #

Arguments

:: (Read a, MonadCGI m) |
=> String | The name of the variable.
-> m (Maybe a) | `Nothing` if the variable does not exist or if the value could not be interpreted at the desired type.

Same as `getInput`, but tries to read the value to the desired type.

getBody :: MonadCGI m => m String Source #

Get the uninterpreted request body as a String

getBodyFPS :: MonadCGI m => m ByteString Source #

Get the uninterpreted request body as lazy ByteString

getInputs :: MonadCGI m => m [(String, String)] Source #

Get the names and values of all inputs. Note: the same name may occur more than once in the output, if there are several values for the name.

getInputsFPS :: MonadCGI m => m [(String, ByteString)] Source #

Get the names and values of all inputs. Note: the same name may occur more than once in the output, if there are several values for the name.

getInputNames :: MonadCGI m => m [String] Source #

Get the names of all input variables.

getMultiInput Source #

Arguments

:: MonadCGI m |
=> String | The name of the variable.
-> m [String] | The values of the variable, or the empty list if the variable was not set.

Get all the values of an input variable, for example from a form. This can be used to get all the values from form controls which allow multiple values to be selected. Example:

    vals <- getMultiInput "my_checkboxes"

getMultiInputFPS Source #

Arguments

:: MonadCGI m |
=> String | The name of the variable.
-> m [ByteString] | The values of the variable, or the empty list if the variable was not set.

Same as `getMultiInput` but using `ByteString`s.

getInputFilename Source #

Arguments

:: MonadCGI m |
=> String | The name of the variable.
-> m (Maybe String) | The file name corresponding to the input, if there is one.

Get the file name of an input.

getInputContentType Source #

Arguments

:: MonadCGI m |
=> String | The name of the variable.
-> m (Maybe String) | The content type, formatted as a string.

Get the content-type of an input, if the input exists, e.g. "image/jpeg". For non-file inputs, this function returns "text/plain". You can use `parseContentType` to get a structured representation of the the content-type value.

# Environment

getVar Source #

Arguments

:: MonadCGI m |
=> String | The name of the variable.
-> m (Maybe String) |

Get the value of a CGI environment variable. Example:

    remoteAddr <- getVar "REMOTE_ADDR"

getVarWithDefault Source #

Arguments

:: MonadCGI m |
=> String | The name of the variable.
-> String | Default value
-> m String |

getVars :: MonadCGI m => m [(String, String)] Source #

Get all CGI environment variables and their values.

# Request information

serverName :: MonadCGI m => m String Source #

The server's hostname, DNS alias, or IP address as it would appear in self-referencing URLs.

serverPort :: MonadCGI m => m Int Source #

The port number to which the request was sent.

requestMethod :: MonadCGI m => m String Source #

The method with which the request was made. For HTTP, this is "GET", "HEAD", "POST", etc.

pathInfo :: MonadCGI m => m String Source #

The extra path information, as given by the client. This is any part of the request path that follows the CGI program path. If the string returned by this function is not empty, it is guaranteed to start with a `'/'`.

Note that this function returns an unencoded string. Make sure to percent-encode any characters that are not allowed in URI paths before using the result of this function to construct a URI. See `progURI`, `queryURI` and `requestURI` for a higher-level interface.

pathTranslated :: MonadCGI m => m String Source #

The path returned by `pathInfo`, but with virtual-to-physical mapping applied to it.

scriptName :: MonadCGI m => m String Source #

A virtual path to the script being executed, used for self-referencing URIs.

Note that this function returns an unencoded string. Make sure to percent-encode any characters that are not allowed in URI paths before using the result of this function to construct a URI. See `progURI`, `queryURI` and `requestURI` for a higher-level interface.

queryString :: MonadCGI m => m String Source #

The information which follows the ? in the URL which referenced this program. This is the percent-encoded query information. For most normal uses, `getInput` and friends are probably more convenient.

remoteHost :: MonadCGI m => m (Maybe String) Source #

The hostname making the request. If the server does not have this information, Nothing is returned. See also `remoteAddr`.

remoteAddr :: MonadCGI m => m String Source #

The IP address of the remote host making the request.

authType :: MonadCGI m => m (Maybe String) Source #

If the server supports user authentication, and the script is protected, this is the protocol-specific authentication method used to validate the user.

remoteUser :: MonadCGI m => m (Maybe String) Source #

If the server supports user authentication, and the script is protected, this is the username they have authenticated as.

requestContentType :: MonadCGI m => m (Maybe String) Source #

For queries which have attached information, such as HTTP POST and PUT, this is the content type of the data. You can use `parseContentType` to get a structured representation of the the content-type value.

requestContentLength :: MonadCGI m => m (Maybe Int) Source #

For queries which have attached information, such as HTTP POST and PUT, this is the length of the content given by the client.

requestHeader :: MonadCGI m => String -> m (Maybe String) Source #

Gets the value of the request header with the given name. The header name is case-insensitive. Example:

    requestHeader "User-Agent"

# Program and request URI

progURI :: MonadCGI m => m URI Source #

Attempts to reconstruct the absolute URI of this program. This does not include any extra path information or query parameters. See `queryURI` for that. If the server is rewriting request URIs, this URI can be different from the one requested by the client. See also `requestURI`.

Characters in the components of the returned URI are escaped when needed, as required by Network.URI.

queryURI :: MonadCGI m => m URI Source #

Like `progURI`, but the returned `URI` also includes any extra path information, and any query parameters. If the server is rewriting request URIs, this URI can be different from the one requested by the client. See also `requestURI`.

Characters in the components of the returned URI are escaped when needed, as required by Network.URI.

requestURI :: MonadCGI m => m URI Source #

Attempts to reconstruct the absolute URI requested by the client, including extra path information and query parameters. If no request URI rewriting is done, or if the web server does not provide the information needed to reconstruct the request URI, this function returns the same value as `queryURI`.

Characters in the components of the returned URI are escaped when needed, as required by Network.URI.

# Content negotiation

class Eq a => Acceptable a Source #

Minimal complete definition

includes

#### Instances

Instances details

Acceptable Charset Source # |
Instance details Defined in Network.CGI.Accept Methods includes :: Charset -> Charset -> Bool
Acceptable ContentEncoding Source # |
Instance details Defined in Network.CGI.Accept Methods includes :: ContentEncoding -> ContentEncoding -> Bool
Acceptable Language Source # |
Instance details Defined in Network.CGI.Accept Methods includes :: Language -> Language -> Bool
Acceptable ContentType Source # |
Instance details Defined in Network.CGI.Accept Methods includes :: ContentType -> ContentType -> Bool

data Accept a Source #

#### Instances

Instances details

Show a => Show (Accept a) Source # |
Instance details Defined in Network.CGI.Accept Methods showsPrec :: Int -> Accept a -> ShowS Source # show :: Accept a -> String Source # showList :: [Accept a] -> ShowS Source #
HeaderValue a => HeaderValue (Accept a) Source # |
Instance details Defined in Network.CGI.Accept Methods parseHeaderValue :: Parser (Accept a) Source # prettyHeaderValue :: Accept a -> String Source #

newtype Charset Source #

Constructors

Charset String |

#### Instances

Instances details

Acceptable Charset Source # |
Instance details Defined in Network.CGI.Accept Methods includes :: Charset -> Charset -> Bool
Show Charset Source # |
Instance details Defined in Network.CGI.Accept Methods showsPrec :: Int -> Charset -> ShowS Source # show :: Charset -> String Source # showList :: [Charset] -> ShowS Source #
Eq Charset Source # |
Instance details Defined in Network.CGI.Accept Methods (==) :: Charset -> Charset -> Bool Source # (/=) :: Charset -> Charset -> Bool Source #
Ord Charset Source # |
Instance details Defined in Network.CGI.Accept Methods compare :: Charset -> Charset -> Ordering Source # (<) :: Charset -> Charset -> Bool Source # (<=) :: Charset -> Charset -> Bool Source # (>) :: Charset -> Charset -> Bool Source # (>=) :: Charset -> Charset -> Bool Source # max :: Charset -> Charset -> Charset Source # min :: Charset -> Charset -> Charset Source #
HeaderValue Charset Source # |
Instance details Defined in Network.CGI.Accept Methods parseHeaderValue :: Parser Charset Source # prettyHeaderValue :: Charset -> String Source #

newtype ContentEncoding Source #

Constructors

ContentEncoding String |

#### Instances

Instances details

Acceptable ContentEncoding Source # |
Instance details Defined in Network.CGI.Accept Methods includes :: ContentEncoding -> ContentEncoding -> Bool
Show ContentEncoding Source # |
Instance details Defined in Network.CGI.Accept Methods showsPrec :: Int -> ContentEncoding -> ShowS Source # show :: ContentEncoding -> String Source # showList :: [ContentEncoding] -> ShowS Source #
Eq ContentEncoding Source # |
Instance details Defined in Network.CGI.Accept Methods (==) :: ContentEncoding -> ContentEncoding -> Bool Source # (/=) :: ContentEncoding -> ContentEncoding -> Bool Source #
Ord ContentEncoding Source # |

Instance details

Defined in Network.CGI.Accept

Methods

compare :: ContentEncoding -> ContentEncoding -> Ordering Source #

(<) :: ContentEncoding -> ContentEncoding -> Bool Source #

(<=) :: ContentEncoding -> ContentEncoding -> Bool Source #

(>) :: ContentEncoding -> ContentEncoding -> Bool Source #

(>=) :: ContentEncoding -> ContentEncoding -> Bool Source #

max :: ContentEncoding -> ContentEncoding -> ContentEncoding Source #

min :: ContentEncoding -> ContentEncoding -> ContentEncoding Source #

HeaderValue ContentEncoding Source # |
Instance details Defined in Network.CGI.Accept Methods parseHeaderValue :: Parser ContentEncoding Source # prettyHeaderValue :: ContentEncoding -> String Source #

newtype Language Source #

Constructors

Language String |

#### Instances

Instances details

Acceptable Language Source # |
Instance details Defined in Network.CGI.Accept Methods includes :: Language -> Language -> Bool
Show Language Source # |
Instance details Defined in Network.CGI.Accept Methods showsPrec :: Int -> Language -> ShowS Source # show :: Language -> String Source # showList :: [Language] -> ShowS Source #
Eq Language Source # |
Instance details Defined in Network.CGI.Accept Methods (==) :: Language -> Language -> Bool Source # (/=) :: Language -> Language -> Bool Source #
Ord Language Source # |
Instance details Defined in Network.CGI.Accept Methods compare :: Language -> Language -> Ordering Source # (<) :: Language -> Language -> Bool Source # (<=) :: Language -> Language -> Bool Source # (>) :: Language -> Language -> Bool Source # (>=) :: Language -> Language -> Bool Source # max :: Language -> Language -> Language Source # min :: Language -> Language -> Language Source #
HeaderValue Language Source # |
Instance details Defined in Network.CGI.Accept Methods parseHeaderValue :: Parser Language Source # prettyHeaderValue :: Language -> String Source #

requestAccept :: MonadCGI m => m (Maybe (Accept ContentType)) Source #

requestAcceptCharset :: MonadCGI m => m (Maybe (Accept Charset)) Source #

requestAcceptEncoding :: MonadCGI m => m (Maybe (Accept ContentEncoding)) Source #

requestAcceptLanguage :: MonadCGI m => m (Maybe (Accept Language)) Source #

negotiate :: Acceptable a => [a] -> Maybe (Accept a) -> [a] Source #

# Content type

data ContentType Source #

A MIME media type value. The `Show` instance is derived automatically. Use `showContentType` to obtain the standard string representation. See http://www.ietf.org/rfc/rfc2046.txt for more information about MIME media types.

Constructors

ContentType |

Fields

- ctType :: String

  The top-level media type, the general type of the data. Common examples are "text", "image", "audio", "video", "multipart", and "application".

- ctSubtype :: String

  The media subtype, the specific data format. Examples include "plain", "html", "jpeg", "form-data", etc.

- ctParameters :: [(String, String)]

  Media type parameters. On common example is the charset parameter for the "text" top-level type, e.g. `("charset","ISO-8859-1")`.

#### Instances

Instances details

Acceptable ContentType Source # |
Instance details Defined in Network.CGI.Accept Methods includes :: ContentType -> ContentType -> Bool
Read ContentType |
Instance details Defined in Network.Multipart.Header Methods readsPrec :: Int -> ReadS ContentType Source # readList :: ReadS [ContentType] Source # readPrec :: ReadPrec ContentType Source # readListPrec :: ReadPrec [ContentType] Source #
Show ContentType |
Instance details Defined in Network.Multipart.Header Methods showsPrec :: Int -> ContentType -> ShowS Source # show :: ContentType -> String Source # showList :: [ContentType] -> ShowS Source #
Eq ContentType |
Instance details Defined in Network.Multipart.Header Methods (==) :: ContentType -> ContentType -> Bool Source # (/=) :: ContentType -> ContentType -> Bool Source #
Ord ContentType |

Instance details

Defined in Network.Multipart.Header

Methods

compare :: ContentType -> ContentType -> Ordering Source #

(<) :: ContentType -> ContentType -> Bool Source #

(<=) :: ContentType -> ContentType -> Bool Source #

(>) :: ContentType -> ContentType -> Bool Source #

(>=) :: ContentType -> ContentType -> Bool Source #

max :: ContentType -> ContentType -> ContentType Source #

min :: ContentType -> ContentType -> ContentType Source #

HeaderValue ContentType |
Instance details Defined in Network.Multipart.Header Methods parseHeaderValue :: Parser ContentType Source # prettyHeaderValue :: ContentType -> String Source #

showContentType :: ContentType -> String Source #

parseContentType :: MonadFail m => String -> m ContentType Source #

Parse the standard representation of a content-type. If the input cannot be parsed, this function calls `fail` with a (hopefully) informative error message.

# Cookies

data Cookie Source #

Contains all information about a cookie set by the server.

Constructors

Cookie |

Fields

- cookieName :: String

  Name of the cookie.

- cookieValue :: String

  Value of the cookie.

- cookieExpires :: Maybe UTCTime

  Expiry date of the cookie. If `Nothing`, the cookie expires when the browser sessions ends. If the date is in the past, the client should delete the cookie immediately.

- cookieDomain :: Maybe String

  The domain suffix to which this cookie will be sent.

- cookiePath :: Maybe String

  The path to which this cookie will be sent.

- cookieSecure :: Bool

  `True` if this cookie should only be sent using secure means.

- cookieHttpOnly :: Bool

  `True` to tell the client's browser to prevent client side scripts from accessing the cookie.

#### Instances

Instances details

Read Cookie Source # |
Instance details Defined in Network.CGI.Cookie Methods readsPrec :: Int -> ReadS Cookie Source # readList :: ReadS [Cookie] Source # readPrec :: ReadPrec Cookie Source # readListPrec :: ReadPrec [Cookie] Source #
Show Cookie Source # |
Instance details Defined in Network.CGI.Cookie Methods showsPrec :: Int -> Cookie -> ShowS Source # show :: Cookie -> String Source # showList :: [Cookie] -> ShowS Source #
Eq Cookie Source # |
Instance details Defined in Network.CGI.Cookie Methods (==) :: Cookie -> Cookie -> Bool Source # (/=) :: Cookie -> Cookie -> Bool Source #
Ord Cookie Source # |
Instance details Defined in Network.CGI.Cookie Methods compare :: Cookie -> Cookie -> Ordering Source # (<) :: Cookie -> Cookie -> Bool Source # (<=) :: Cookie -> Cookie -> Bool Source # (>) :: Cookie -> Cookie -> Bool Source # (>=) :: Cookie -> Cookie -> Bool Source # max :: Cookie -> Cookie -> Cookie Source # min :: Cookie -> Cookie -> Cookie Source #

newCookie Source #

Arguments

:: String | Name
-> String | Value
-> Cookie | Cookie

Construct a cookie with only name and value set. This client will expire when the browser sessions ends, will only be sent to the server and path which set it and may be sent using any means.

getCookie Source #

Arguments

:: MonadCGI m |
=> String | The name of the cookie.
-> m (Maybe String) | `Nothing` if the cookie does not exist.

Get the value of a cookie.

readCookie Source #

Arguments

:: (Read a, MonadCGI m) |
=> String | The name of the cookie.
-> m (Maybe a) | `Nothing` if the cookie does not exist or if the value could not be interpreted at the desired type.

Same as `getCookie`, but tries to read the value to the desired type.

setCookie :: MonadCGI m => Cookie -> m () Source #

Set a cookie.

deleteCookie :: MonadCGI m => Cookie -> m () Source #

Delete a cookie from the client

# URL encoding

formEncode :: [(String, String)] -> String Source #

Formats name-value pairs as application/x-www-form-urlencoded.

urlEncode :: String -> String Source #

Converts a single value to the application/x-www-form-urlencoded encoding.

formDecode :: String -> [(String, String)] Source #

Gets the name-value pairs from application/x-www-form-urlencoded data.

urlDecode :: String -> String Source #

Converts a single value from the application/x-www-form-urlencoded encoding.