http-types 0.12.1 → 0.12.2
raw patch · 4 files changed
+37/−19 lines, 4 files
Files
- CHANGELOG +6/−0
- Network/HTTP/Types/Header.hs +7/−0
- Network/HTTP/Types/URI.hs +22/−17
- http-types.cabal +2/−2
CHANGELOG view
@@ -1,3 +1,9 @@+* 0.12.2 [2018-09-26]++Add new parseQueryReplacePlus function, which allows specifying whether to replace '+' with ' '.++Add header name constants for "Prefer" and "Preference-Applied" (RFC 7240).+ * 0.12.1 [2018-01-31] Add new functions for constructing a query URI where not all parts are escaped.
Network/HTTP/Types/Header.hs view
@@ -40,6 +40,8 @@ , hMaxForwards , hOrigin , hPragma+, hPrefer+, hPreferenceApplied , hProxyAuthenticate , hProxyAuthorization , hRange@@ -158,6 +160,11 @@ -- | HTTP Header names according to https://tools.ietf.org/html/rfc6454 hOrigin :: HeaderName hOrigin = "Origin"++-- | HTTP Header names according to https://tools.ietf.org/html/rfc7240+hPrefer, hPreferenceApplied :: HeaderName+hPrefer = "Prefer"+hPreferenceApplied = "Preference-Applied" -- | RFC 2616 Byte range (individual). --
Network/HTTP/Types/URI.hs view
@@ -11,6 +11,7 @@ , renderQueryBuilder , renderSimpleQuery , parseQuery+, parseQueryReplacePlus , parseSimpleQuery -- **Escape only parts , renderQueryPartialEscape@@ -61,8 +62,8 @@ -- | Query. -- --- General form: a=b&c=d, but if the value is Nothing, it becomes--- a&c=d.+-- General form: @a=b&c=d@, but if the value is Nothing, it becomes+-- @a&c=d@. type Query = [QueryItem] -- | Like Query, but with 'Text' instead of 'B.ByteString' (UTF8-encoded).@@ -137,10 +138,17 @@ -- 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".+-- * Percent decoding errors are ignored. In particular, @"%Q"@ will be output as+-- @"%Q"@.+--+-- * It decodes @\'+\'@ characters to @\' \'@ parseQuery :: B.ByteString -> Query-parseQuery = parseQueryString' . dropQuestion+parseQuery = parseQueryReplacePlus True++-- | Same functionality as 'parseQuery' with the option to decode @\'+\'@ characters to @\' \'@+-- or preserve @\'+\'@+parseQueryReplacePlus :: Bool -> B.ByteString -> Query+parseQueryReplacePlus replacePlus bs = parseQueryString' $ dropQuestion bs where dropQuestion q = case B.uncons q of@@ -155,9 +163,9 @@ let (k, v) = B.break (== 61) x -- equal sign v'' = case B.uncons v of- Just (_, v') -> Just $ urlDecode True v'+ Just (_, v') -> Just $ urlDecode replacePlus v' _ -> Nothing- in (urlDecode True k, v'')+ in (urlDecode replacePlus k, v'') queryStringSeparators :: B.ByteString queryStringSeparators = B.pack [38,59] -- ampersand, semicolon@@ -207,13 +215,13 @@ urlEncodeBuilder False = urlEncodeBuilder' unreservedPI -- | Percent-encoding for URLs.-urlEncode :: Bool -- ^ Whether to decode '+' to ' '+urlEncode :: Bool -- ^ Whether to decode @\'+\'@ to @\' \'@ -> B.ByteString -- ^ The ByteString to encode as URL -> B.ByteString -- ^ The encoded URL urlEncode q = BL.toStrict . B.toLazyByteString . urlEncodeBuilder q -- | Percent-decoding.-urlDecode :: Bool -- ^ Whether to decode '+' to ' '+urlDecode :: Bool -- ^ Whether to decode @\'+\'@ to @\' \'@ -> B.ByteString -> B.ByteString urlDecode replacePlus z = fst $ B.unfoldrN (B.length z) go z where@@ -242,22 +250,19 @@ -- -- * UTF-8 encodes the characters. -- --- * Performs percent encoding on all unreserved characters, as well as \:\@\=\+\$,+-- * Performs percent encoding on all unreserved characters, as well as @\:\@\=\+\$@, -- -- * Prepends each segment with a slash. -- -- For example: -- -- > encodePathSegments [\"foo\", \"bar\", \"baz\"]--- -- \"\/foo\/bar\/baz\" -- -- > encodePathSegments [\"foo bar\", \"baz\/bin\"]--- -- \"\/foo\%20bar\/baz\%2Fbin\" -- -- > encodePathSegments [\"שלום\"]--- -- \"\/%D7%A9%D7%9C%D7%95%D7%9D\" -- -- Huge thanks to Jeremy Shaw who created the original implementation of this@@ -333,12 +338,12 @@ ----------------------------------------------------------------------------------------- -- | For some URIs characters must not be URI encoded,--- eg '+' or ':' in q=a+language:haskell+created:2009-01-01..2009-02-01&sort=stars+-- e.g. @\'+\'@ or @\':\'@ in @q=a+language:haskell+created:2009-01-01..2009-02-01&sort=stars@ -- The character list unreservedPI instead of unreservedQS would solve this. -- But we explicitly decide what part to encode.--- This is mandatory when searching for '+': q=%2B+language:haskell.+-- This is mandatory when searching for @\'+\'@: @q=%2B+language:haskell@. data EscapeItem = QE B.ByteString -- will be URL encoded- | QN B.ByteString -- will not be url encoded, eg '+' or ':'+ | QN B.ByteString -- will not be url encoded, e.g. @\'+\'@ or @\':\'@ deriving (Show, Eq, Ord) -- | Query item@@ -346,7 +351,7 @@ -- | Query with some chars that should not be escaped. -- --- General form: a=b&c=d:e+f&g=h+-- General form: @a=b&c=d:e+f&g=h@ type PartialEscapeQuery = [PartialEscapeQueryItem] -- | Convert 'PartialEscapeQuery' to 'ByteString'.
http-types.cabal view
@@ -1,5 +1,5 @@ Name: http-types-Version: 0.12.1+Version: 0.12.2 Synopsis: Generic HTTP types for Haskell (for both client and server code). Description: Generic HTTP types for Haskell (for both client and server code). Homepage: https://github.com/aristidb/http-types@@ -16,7 +16,7 @@ Source-repository this type: git location: https://github.com/aristidb/http-types.git- tag: 0.12.1+ tag: 0.12.2 Source-repository head type: git