web-encodings-0.2.5: Encapsulate multiple web encoding in a single package.Source codeContentsIndex
Web.Encodings
Portabilityportable
StabilityStable
MaintainerMichael Snoyman <michael@snoyman.com>
Contents
Simple encodings.
URL (percentage encoding)
HTML (entity encoding)
JSON
HTTP level encoding.
Query string- pairs of percentage encoding
Post parameters
Specific HTTP headers
Date/time encoding
WAI-specific decodings
Description
Various web encodings.
Synopsis
encodeUrl :: StringLike a => a -> a
decodeUrl :: StringLike s => s -> s
decodeUrlFailure :: (MonadFailure DecodeUrlException m, StringLike s) => s -> m s
data DecodeUrlException
= InvalidPercentEncoding
| InvalidUtf8Encoding
encodeHtml :: StringLike s => s -> s
decodeHtml :: StringLike s => s -> s
encodeJson :: StringLike s => s -> s
decodeJson :: StringLike s => s -> s
encodeUrlPairs :: StringLike s => [(s, s)] -> s
decodeUrlPairs :: StringLike s => s -> [(s, s)]
decodeUrlPairsFailure :: (StringLike s, MonadFailure DecodeUrlException m) => s -> m [(s, s)]
data FileInfo s c = FileInfo {
fileName :: s
fileContentType :: s
fileContent :: c
}
parseMultipart :: StringLike s => String -> s -> ([(s, s)], [(s, FileInfo s s)])
parsePost :: StringLike s => String -> String -> s -> ([(s, s)], [(s, FileInfo s s)])
decodeCookies :: StringLike s => s -> [(s, s)]
parseCookies :: StringLike s => s -> [(s, s)]
parseHttpAccept :: StringLike s => s -> [s]
formatW3 :: UTCTime -> String
parseRequestBody :: Sink x y -> Request -> IO ([(ByteString, ByteString)], [(ByteString, FileInfo ByteString y)])
data Sink x y = Sink {
sinkInit :: IO x
sinkAppend :: x -> ByteString -> IO x
sinkClose :: x -> IO y
sinkFinalize :: y -> IO ()
}
lbsSink :: Sink ([ByteString] -> [ByteString]) ByteString
tempFileSink :: Sink (FilePath, Handle) FilePath
Simple encodings.
URL (percentage encoding)
encodeUrl :: StringLike a => a -> aSource

Encode all but unreserved characters with percentage encoding.

This function implicitly converts the given value to a UTF-8 bytestream.

decodeUrl :: StringLike s => s -> sSource

Decode percentage encoding. Assumes use of UTF-8 character encoding.

If there are any parse errors, this returns the original input. If you would like to be alerted more directly of errors, use decodeUrlFailure.

decodeUrlFailure :: (MonadFailure DecodeUrlException m, StringLike s) => s -> m sSource
Same as decodeUrl, but failures on either invalid percent or UTF8 encoding.
data DecodeUrlException Source
Constructors
InvalidPercentEncoding
InvalidUtf8Encoding
show/hide Instances
HTML (entity encoding)
encodeHtml :: StringLike s => s -> sSource
Escape special HTML characters.
decodeHtml :: StringLike s => s -> sSource

Decode HTML-encoded content into plain content.

Note: this does not support all HTML entities available. It also swallows all failures.

JSON
encodeJson :: StringLike s => s -> sSource
Perform JSON-encoding on a string. Does not wrap in quotation marks. Taken from json package by Sigbjorn Finne.
decodeJson :: StringLike s => s -> sSource
HTTP level encoding.
Query string- pairs of percentage encoding
encodeUrlPairs :: StringLike s => [(s, s)] -> sSource
Convert a list of key-values pairs into a query string. Does not include the question mark at the beginning.
decodeUrlPairs :: StringLike s => s -> [(s, s)]Source
Convert into key-value pairs. Strips the leading ? if necesary.
decodeUrlPairsFailure :: (StringLike s, MonadFailure DecodeUrlException m) => s -> m [(s, s)]Source
Convert into key-value pairs. Strips the leading ? if necesary. failures as necesary for invalid encodings.
Post parameters
data FileInfo s c Source
Information on an uploaded file.
Constructors
FileInfo
fileName :: s
fileContentType :: s
fileContent :: c
show/hide Instances
(Eq s, Eq c) => Eq (FileInfo s c)
(Show s, Show c) => Show (FileInfo s c)
parseMultipartSource
:: StringLike s
=> Stringboundary
-> scontent
-> ([(s, s)], [(s, FileInfo s s)])
Parse a multipart form into parameters and files.
parsePostSource
:: StringLike s
=> Stringcontent type
-> Stringcontent length
-> sbody of the post
-> ([(s, s)], [(s, FileInfo s s)])
Parse a post request. This function determines the correct decoding function to use.
Specific HTTP headers
decodeCookies :: StringLike s => s -> [(s, s)]Source
Deprecate alias for parseCookies.
parseCookies :: StringLike s => s -> [(s, s)]Source
Decode the value of an HTTP_COOKIE header into key/value pairs.
parseHttpAccept :: StringLike s => s -> [s]Source
Parse the HTTP accept string to determine supported content types.
Date/time encoding
formatW3 :: UTCTime -> StringSource
Format a UTCTime in W3 format; useful for setting cookies.
WAI-specific decodings
parseRequestBody :: Sink x y -> Request -> IO ([(ByteString, ByteString)], [(ByteString, FileInfo ByteString y)])Source

This function works just like parsePost, which two important distinctions:

  • It runs on a Source, which is the datatype used by the WAI for feeding a request body.
  • It allows you to specify a Sink for receiving each individual file parameter, so that you can avoid allocating large amounts of memory if desired.

Remember that it is your obligation to call sinkFinalize on the returned values.

data Sink x y Source
A destination for data, the opposite of a Source.
Constructors
Sink
sinkInit :: IO x
sinkAppend :: x -> ByteString -> IO x
sinkClose :: x -> IO y
sinkFinalize :: y -> IO ()
lbsSink :: Sink ([ByteString] -> [ByteString]) ByteStringSource
tempFileSink :: Sink (FilePath, Handle) FilePathSource
Produced by Haddock version 2.6.1