http-types-0.8.0: Generic HTTP types for Haskell (for both client and server code).

Safe HaskellNone




Query string

type Query = [QueryItem]Source


General form: a=b&c=d, but if the value is Nothing, it becomes a&c=d.

type SimpleQueryItem = (ByteString, ByteString)Source

Simplified Query item type without support for parameter-less items.

type SimpleQuery = [SimpleQueryItem]Source

Simplified Query type without support for parameter-less items.



:: Bool

prepend question mark?

-> Query 
-> ByteString 

Convert Query to ByteString.



:: Bool

prepend a question mark?

-> Query 
-> Builder 

Convert Query to a Builder.



:: Bool

prepend question mark?

-> SimpleQuery 
-> ByteString 

Convert SimpleQuery to ByteString.

parseQuery :: ByteString -> QuerySource

Split out the query string into a list of keys and values. A few importants points:

  • The result returned is still bytestrings, since we perform no character decoding here. Most likely, you will want to use UTF-8 decoding, but this is left to the user of the library.
  • Percent decoding errors are ignored. In particular, %Q will be output as %Q.

Text query string (UTF8 encoded)

type QueryText = [(Text, Maybe Text)]Source

Like Query, but with Text instead of ByteString (UTF8-encoded).

queryToQueryText :: Query -> QueryTextSource

Convert Query to QueryText (leniently decoding the UTF-8).



:: Bool

prepend a question mark?

-> QueryText 
-> Builder 

Convert QueryText to a Builder.

Path segments

encodePathSegments :: [Text] -> BuilderSource

Encodes a list of path segments into a valid URL fragment.

This function takes the following three steps:

  • UTF-8 encodes the characters.
  • Performs percent encoding on all unreserved characters, as well as :@=+$,
  • Prepends each segment with a slash.

For example:

 encodePathSegments [\"foo\", \"bar\", \"baz\"]


 encodePathSegments [\"foo bar\", \"baz\/bin\"]


 encodePathSegments [\"שלום\"]


Huge thanks to Jeremy Shaw who created the original implementation of this function in web-routes and did such thorough research to determine all correct escaping procedures.

decodePathSegments :: ByteString -> [Text]Source

Parse a list of path segments from a valid URL fragment.

encodePathSegmentsRelative :: [Text] -> BuilderSource

Like encodePathSegments, but without the initial slash.

Path (segments + query string)

encodePath :: [Text] -> Query -> BuilderSource

Encode a whole path (path segments + query).

decodePath :: ByteString -> ([Text], Query)Source

Decode a whole path (path segments + query).

URL encoding / decoding



:: Bool

Whether input is in query string. True: Query string, False: Path element

-> ByteString 
-> Builder 

Percent-encoding for URLs (using Builder).

urlEncode :: Bool -> ByteString -> ByteStringSource

Percent-encoding for URLs.



:: Bool

Whether to decode + to ' '

-> ByteString 
-> ByteString