Safe Haskell | None |
---|
An internal Snap module containing HTTP types.
N.B. this is an internal interface, please don't write user code that depends on it. Most of these declarations (except for the unsafe/encapsulation-breaking ones) are re-exported from Snap.Core.
- set_c_locale :: IO ()
- c_parse_http_time :: CString -> IO CTime
- c_format_http_time :: CTime -> CString -> IO ()
- c_format_log_time :: CTime -> CString -> IO ()
- class HasHeaders a where
- updateHeaders :: (Headers -> Headers) -> a -> a
- headers :: a -> Headers
- addHeader :: HasHeaders a => CI ByteString -> ByteString -> a -> a
- setHeader :: HasHeaders a => CI ByteString -> ByteString -> a -> a
- getHeaders :: HasHeaders a => CI ByteString -> a -> Maybe [ByteString]
- getHeader :: HasHeaders a => CI ByteString -> a -> Maybe ByteString
- listHeaders :: HasHeaders a => a -> [(CI ByteString, ByteString)]
- deleteHeader :: HasHeaders a => CI ByteString -> a -> a
- data Method
- type HttpVersion = (Int, Int)
- data Cookie = Cookie {
- cookieName :: !ByteString
- cookieValue :: !ByteString
- cookieExpires :: !(Maybe UTCTime)
- cookieDomain :: !(Maybe ByteString)
- cookiePath :: !(Maybe ByteString)
- cookieSecure :: !Bool
- cookieHttpOnly :: !Bool
- type Params = Map ByteString [ByteString]
- newtype SomeEnumerator = SomeEnumerator (forall a. Enumerator ByteString IO a)
- data Request = Request {
- rqServerName :: ByteString
- rqServerPort :: !Int
- rqRemoteAddr :: ByteString
- rqRemotePort :: Int
- rqLocalAddr :: ByteString
- rqLocalPort :: Int
- rqLocalHostname :: ByteString
- rqIsSecure :: Bool
- rqHeaders :: Headers
- rqBody :: !(IORef SomeEnumerator)
- rqContentLength :: !(Maybe Int)
- rqMethod :: !Method
- rqVersion :: HttpVersion
- rqCookies :: [Cookie]
- rqPathInfo :: !ByteString
- rqContextPath :: !ByteString
- rqURI :: !ByteString
- rqQueryString :: !ByteString
- rqParams :: Params
- rqQueryParams :: Params
- rqPostParams :: Params
- data ResponseBody
- rspBodyMap :: (forall a. Enumerator Builder IO a -> Enumerator Builder IO a) -> ResponseBody -> ResponseBody
- rspBodyToEnum :: ResponseBody -> Enumerator Builder IO a
- data Response = Response {}
- rqParam :: ByteString -> Request -> Maybe [ByteString]
- rqPostParam :: ByteString -> Request -> Maybe [ByteString]
- rqQueryParam :: ByteString -> Request -> Maybe [ByteString]
- rqModifyParams :: (Params -> Params) -> Request -> Request
- rqSetParam :: ByteString -> [ByteString] -> Request -> Request
- emptyResponse :: Response
- setResponseBody :: (forall a. Enumerator Builder IO a) -> Response -> Response
- setResponseStatus :: Int -> ByteString -> Response -> Response
- setResponseCode :: Int -> Response -> Response
- modifyResponseBody :: (forall a. Enumerator Builder IO a -> Enumerator Builder IO a) -> Response -> Response
- setContentType :: ByteString -> Response -> Response
- addResponseCookie :: Cookie -> Response -> Response
- getResponseCookie :: ByteString -> Response -> Maybe Cookie
- getResponseCookies :: Response -> [Cookie]
- deleteResponseCookie :: ByteString -> Response -> Response
- modifyResponseCookie :: ByteString -> (Cookie -> Cookie) -> Response -> Response
- setContentLength :: Int64 -> Response -> Response
- clearContentLength :: Response -> Response
- getBufferingMode :: Response -> Bool
- setBufferingMode :: Bool -> Response -> Response
- formatHttpTime :: CTime -> IO ByteString
- formatLogTime :: CTime -> IO ByteString
- parseHttpTime :: ByteString -> IO CTime
- fromStr :: String -> ByteString
- toStr :: ByteString -> String
- statusReasonMap :: IntMap ByteString
Documentation
set_c_locale :: IO ()Source
c_format_http_time :: CTime -> CString -> IO ()Source
c_format_log_time :: CTime -> CString -> IO ()Source
class HasHeaders a whereSource
A typeclass for datatypes which contain HTTP headers.
updateHeaders :: (Headers -> Headers) -> a -> aSource
Modify the datatype's headers.
Retrieve the headers from a datatype that has headers.
addHeader :: HasHeaders a => CI ByteString -> ByteString -> a -> aSource
Adds a header key-value-pair to the HasHeaders
datatype. If a header
with the same name already exists, the new value is appended to the headers
list.
setHeader :: HasHeaders a => CI ByteString -> ByteString -> a -> aSource
Sets a header key-value-pair in a HasHeaders
datatype. If a header with
the same name already exists, it is overwritten with the new value.
getHeaders :: HasHeaders a => CI ByteString -> a -> Maybe [ByteString]Source
Gets all of the values for a given header.
getHeader :: HasHeaders a => CI ByteString -> a -> Maybe ByteStringSource
Gets a header value out of a HasHeaders
datatype. If many headers came
in with the same name, they will be catenated together.
listHeaders :: HasHeaders a => a -> [(CI ByteString, ByteString)]Source
Lists all the headers out of a HasHeaders
datatype. If many
headers came in with the same name, they will be catenated together.
deleteHeader :: HasHeaders a => CI ByteString -> a -> aSource
Clears a header value from a HasHeaders
datatype.
Enumerates the HTTP method values (see http://tools.ietf.org/html/rfc2068.html#section-5.1.1).
type HttpVersion = (Int, Int)Source
A datatype representing an HTTP cookie.
Cookie | |
|
type Params = Map ByteString [ByteString]Source
A type alias for the HTTP parameters mapping. Each parameter
key maps to a list of ByteString values; if a parameter is specified
multiple times (e.g.: "GET /foo?param=bar1¶m=bar2
"), looking up
"param
" in the mapping will give you ["bar1", "bar2"]
.
newtype SomeEnumerator Source
An existential wrapper for the 'Enumerator ByteString IO a' type
SomeEnumerator (forall a. Enumerator ByteString IO a) |
Contains all of the information about an incoming HTTP request.
Request | |
|
Show Request | |
HasHeaders Request | |
Monad m => MonadState Request (RequestBuilder m) |
data ResponseBody Source
rspBodyMap :: (forall a. Enumerator Builder IO a -> Enumerator Builder IO a) -> ResponseBody -> ResponseBodySource
Represents an HTTP response.
Response | |
|
:: ByteString | parameter name to look up |
-> Request | HTTP request |
-> Maybe [ByteString] |
Looks up the value(s) for the given named parameter. Parameters initially
come from the request's query string and any decoded POST body (if the
request's Content-Type
is application/x-www-form-urlencoded
).
Parameter values can be modified within handlers using rqModifyParams.
:: ByteString | parameter name to look up |
-> Request | HTTP request |
-> Maybe [ByteString] |
Looks up the value(s) for the given named parameter in the POST parameters mapping.
:: ByteString | parameter name to look up |
-> Request | HTTP request |
-> Maybe [ByteString] |
Looks up the value(s) for the given named parameter in the query parameters mapping.
rqModifyParams :: (Params -> Params) -> Request -> RequestSource
Modifies the parameters mapping (which is a Map ByteString ByteString
)
in a Request
using the given function.
:: ByteString | parameter name |
-> [ByteString] | parameter values |
-> Request | request |
-> Request |
Writes a key-value pair to the parameters mapping within the given request.
emptyResponse :: ResponseSource
An empty Response
.
:: (forall a. Enumerator Builder IO a) | new response body enumerator |
-> Response | response to modify |
-> Response |
Sets an HTTP response body to the given Enumerator
value.
:: Int | HTTP response integer code |
-> ByteString | HTTP response explanation |
-> Response | Response to be modified |
-> Response |
Sets the HTTP response status. Note: normally you would use
setResponseCode
unless you needed a custom response explanation.
Sets the HTTP response code.
modifyResponseBody :: (forall a. Enumerator Builder IO a -> Enumerator Builder IO a) -> Response -> ResponseSource
Modifies a response body.
setContentType :: ByteString -> Response -> ResponseSource
Sets the Content-Type
in the Response
headers.
:: ByteString | cookie name |
-> Response | response to query |
-> Maybe Cookie |
:: ByteString | cookie name |
-> Response | response to modify |
-> Response |
:: ByteString | cookie name |
-> (Cookie -> Cookie) | modifier function |
-> Response | response to modify |
-> Response |
setContentLength :: Int64 -> Response -> ResponseSource
A note here: if you want to set the Content-Length
for the response,
Snap forces you to do it with this function rather than by setting it in
the headers; the Content-Length
in the headers will be ignored.
The reason for this is that Snap needs to look up the value of
Content-Length
for each request, and looking the string value up in the
headers and parsing the number out of the text will be too expensive.
If you don't set a content length in your response, HTTP keep-alive will be
disabled for HTTP/1.0 clients, forcing a Connection: close
. For
HTTP/1.1 clients, Snap will switch to the chunked transfer encoding if
Content-Length
is not specified.
clearContentLength :: Response -> ResponseSource
Removes any Content-Length
set in the Response
.
getBufferingMode :: Response -> BoolSource
The buffering mode controls whether Snap will buffer the output or not. You may wish to disable buffering when using Comet-like techniques which rely on the immediate sending of output data in order to maintain interactive semantics.
The buffering mode controls whether Snap will buffer the output or not. You may wish to disable buffering when using Comet-like techniques which rely on the immediate sending of output data in order to maintain interactive semantics.
formatHttpTime :: CTime -> IO ByteStringSource
Converts a CTime
into an HTTP timestamp.
formatLogTime :: CTime -> IO ByteStringSource
Converts a CTime
into common log entry format.
parseHttpTime :: ByteString -> IO CTimeSource
Converts an HTTP timestamp into a CTime
.
fromStr :: String -> ByteStringSource
toStr :: ByteString -> StringSource