Copyright | (c) 2010 Jeremy Shaw |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | partners@seereason.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
Conversions between raw pathinfos and decoded path segments.
- encodePathInfo :: [Text] -> [(Text, Maybe Text)] -> Text
- decodePathInfo :: ByteString -> [Text]
- decodePathInfoParams :: ByteString -> ([Text], [(Text, Maybe Text)])
Documentation
encodePathInfo :: [Text] -> [(Text, Maybe Text)] -> Text Source #
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 :@=+$,
- Intercalates with a slash.
For example:
encodePathInfo [\"foo\", \"bar\", \"baz\"]
"foo/bar/baz"
encodePathInfo [\"foo bar\", \"baz\/bin\"]
"foo%20bar/baz%2Fbin"
encodePathInfo [\"שלום\"]
"%D7%A9%D7%9C%D7%95%D7%9D"
decodePathInfo :: ByteString -> [Text] Source #
Performs the inverse operation of encodePathInfo
.
In particular, this function:
- Splits a string at each occurence of a forward slash.
- Percent-decodes the individual pieces.
- UTF-8 decodes the resulting data.
This utilizes decodeString
from the utf8-string library, and thus all UTF-8
decoding errors are handled as per that library.
In general, you will want to strip the leading slash from a pathinfo before passing it to this function. For example:
decodePathInfo \"\"
[]
decodePathInfo \"\/\"
- ""
Note that while function accepts a Text
value, it is expected that Text
will only contain the subset of characters which are allowed to appear in a URL.
decodePathInfoParams :: ByteString -> ([Text], [(Text, Maybe Text)]) Source #
Returns path segments as well as possible query string components
For example:
decodePathInfoParams "/home?q=1"
(["home"],[("q",Just "1")])