| Haskell Hierarchical Libraries (cgi package) | Source code | Contents | Index

Network.CGI.Protocol |

Portability | non-portable
Stability | experimental
Maintainer | bjorn@bringert.net

Contents

CGI request
CGI response
Running CGI actions
Inputs
Environment variables
Logging
URL encoding
Utilities

Description
An implementation of the program side of the CGI protocol.
Synopsis

data CGIRequest = CGIRequest {

cgiVars :: (Map String String)
cgiInputs :: [(String, Input)]
cgiRequestBody :: ByteString

}
data Input = Input {

inputValue :: ByteString
inputFilename :: (Maybe String)
inputContentType :: ContentType

}

data CGIResult

= CGIOutput ByteString
| CGINothing

type Headers = [(HeaderName, String)]
newtype HeaderName = HeaderName String
hRunCGI :: MonadIO m => [(String, String)] -> Handle -> Handle -> (CGIRequest -> m (Headers, CGIResult)) -> m ()
runCGIEnvFPS :: Monad m => [(String, String)] -> ByteString -> (CGIRequest -> m (Headers, CGIResult)) -> m ByteString
decodeInput :: [(String, String)] -> ByteString -> [(String, Input)]
takeInput :: [(String, String)] -> ByteString -> ByteString
getCGIVars :: MonadIO m => m [(String, String)]
logCGI :: MonadIO m => String -> m ()
formEncode :: [(String, String)] -> String
urlEncode :: String -> String
formDecode :: String -> [(String, String)]
urlDecode :: String -> String
maybeRead :: Read a => String -> Maybe a
replace :: Eq a => a -> a -> [a] -> [a]

CGI request
data CGIRequest

The input to a CGI action.
Constructors

CGIRequest |

cgiVars :: (Map String String) | Environment variables.
cgiInputs :: [(String, Input)] | Input parameters. For better laziness in reading inputs, this is not a Map.
cgiRequestBody :: ByteString | Raw request body.

Instances

Show CGIRequest

data Input

The value of an input parameter, and some metadata.
Constructors

Input |

inputValue :: ByteString |
inputFilename :: (Maybe String) |
inputContentType :: ContentType |

Instances

Show Input

CGI response
data CGIResult

The result of a CGI program.
Constructors

CGIOutput ByteString |
CGINothing |

Instances

Eq CGIResult
Ord CGIResult
Read CGIResult
Show CGIResult

type Headers = [(HeaderName, String)]
newtype HeaderName

A string with case insensitive equality and comparisons.
Constructors

HeaderName String |

Instances

Eq HeaderName
Ord HeaderName
Show HeaderName

Running CGI actions
hRunCGI

:: MonadIO m |
=> [(String, String)] | CGI environment variables.
-> Handle | Handle that input will be read from.
-> Handle | Handle that output will be written to.
-> (CGIRequest -> m (Headers, CGIResult)) | CGI action
-> m () |
Run a CGI action. Gets CGI environment variables from the program environment.

runCGIEnvFPS

:: Monad m |
=> [(String, String)] | CGI environment variables.
-> ByteString | Request body.
-> (CGIRequest -> m (Headers, CGIResult)) | CGI action.
-> m ByteString | Response (headers and content).
Run a CGI action in a given environment, using a `ByteString` for input and a lazy string for output.

Inputs
decodeInput

:: [(String, String)] | CGI environment variables.
-> ByteString | Request body.
-> [(String, Input)] | Input variables and values.
Get and decode the input according to the request method and the content-type.

takeInput

:: [(String, String)] | CGI environment variables.
-> ByteString | Request body.
-> ByteString | CONTENT_LENGTH bytes from the request body, or the empty string if there is no CONTENT_LENGTH.
Take the right number of bytes from the input.

Environment variables
getCGIVars :: MonadIO m => m [(String, String)]
Logging
logCGI :: MonadIO m => String -> m ()
Log 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?
URL encoding
formEncode :: [(String, String)] -> String
Format name-value pairs as application/x-www-form-urlencoded.
urlEncode :: String -> String
Convert a single value to the application/x-www-form-urlencoded encoding.
formDecode :: String -> [(String, String)]
Get the name-value pairs from application/x-www-form-urlencoded data.
urlDecode :: String -> String
Convert a single value from the application/x-www-form-urlencoded encoding.
Utilities
maybeRead :: Read a => String -> Maybe a
replace

:: Eq a |
=> a | Value to look for
-> a | Value to replace it with
-> [a] | Input list
-> [a] | Output list
Replace all instances of a value in a list by another value.

Produced by Haddock version 0.8