http-types 0.10 → 0.11
raw patch · 6 files changed
+65/−47 lines, 6 filesdep −blaze-builderdep ~bytestringPVP ok
version bump matches the API change (PVP)
Dependencies removed: blaze-builder
Dependency ranges changed: bytestring
API changes (from Hackage documentation)
+ Network.HTTP.Types: http20 :: HttpVersion
+ Network.HTTP.Types: networkAuthenticationRequired511 :: Status
+ Network.HTTP.Types: permanentRedirect308 :: Status
+ Network.HTTP.Types: preconditionRequired428 :: Status
+ Network.HTTP.Types: requestHeaderFieldsTooLarge431 :: Status
+ Network.HTTP.Types: status308 :: Status
+ Network.HTTP.Types: status422 :: Status
+ Network.HTTP.Types: status428 :: Status
+ Network.HTTP.Types: status429 :: Status
+ Network.HTTP.Types: status431 :: Status
+ Network.HTTP.Types: status511 :: Status
+ Network.HTTP.Types: tooManyRequests429 :: Status
+ Network.HTTP.Types: unprocessableEntity422 :: Status
+ Network.HTTP.Types.Status: instance GHC.Enum.Bounded Network.HTTP.Types.Status.Status
Files
- CHANGELOG +8/−0
- Network/HTTP/Types.hs +14/−1
- Network/HTTP/Types/Header.hs +11/−11
- Network/HTTP/Types/Status.hs +5/−1
- Network/HTTP/Types/URI.hs +24/−29
- http-types.cabal +3/−5
CHANGELOG view
@@ -1,3 +1,11 @@+* 0.11 [2017-11-29]++Remove dependency on blaze-builder. (Note that as a side effect of this, URI encoding is now using lower-case rather than uppercase hexadecimal.)++Add Bounded instance to Status.++Re-export more status codes and http20 from Network.HTTP.Types.+ * 0.10 [2017-10-22] New status codes, new headers.
Network/HTTP/Types.hs view
@@ -21,7 +21,8 @@ , http09 , http10 , http11- -- * Status+, http20+-- * Status , Status(..) , mkStatus , status100@@ -56,6 +57,8 @@ , useProxy305 , status307 , temporaryRedirect307+, status308+, permanentRedirect308 , status400 , badRequest400 , status401@@ -94,6 +97,14 @@ , expectationFailed417 , status418 , imATeapot418+, status422+, unprocessableEntity422+, status428+, preconditionRequired428+, status429+, tooManyRequests429+, status431+, requestHeaderFieldsTooLarge431 , status500 , internalServerError500 , status501@@ -106,6 +117,8 @@ , gatewayTimeout504 , status505 , httpVersionNotSupported505+, status511+, networkAuthenticationRequired511 , statusIsInformational , statusIsSuccessful , statusIsRedirection
Network/HTTP/Types/Header.hs view
@@ -74,10 +74,10 @@ #if __GLASGOW_HASKELL__ < 710 import Data.Monoid #endif-import qualified Blaze.ByteString.Builder as Blaze-import qualified Blaze.ByteString.Builder.Char8 as Blaze import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as B8+import qualified Data.ByteString.Builder as B+import qualified Data.ByteString.Lazy as BL import qualified Data.CaseInsensitive as CI import Data.ByteString.Char8 () {-IsString-} import Data.Typeable (Typeable)@@ -168,23 +168,23 @@ | ByteRangeSuffix !Integer deriving (Show, Eq, Ord, Typeable, Data) -renderByteRangeBuilder :: ByteRange -> Blaze.Builder-renderByteRangeBuilder (ByteRangeFrom from) = Blaze.fromShow from `mappend` Blaze.fromChar '-'-renderByteRangeBuilder (ByteRangeFromTo from to) = Blaze.fromShow from `mappend` Blaze.fromChar '-' `mappend` Blaze.fromShow to-renderByteRangeBuilder (ByteRangeSuffix suffix) = Blaze.fromChar '-' `mappend` Blaze.fromShow suffix+renderByteRangeBuilder :: ByteRange -> B.Builder+renderByteRangeBuilder (ByteRangeFrom from) = B.integerDec from `mappend` B.char7 '-'+renderByteRangeBuilder (ByteRangeFromTo from to) = B.integerDec from `mappend` B.char7 '-' `mappend` B.integerDec to+renderByteRangeBuilder (ByteRangeSuffix suffix) = B.char7 '-' `mappend` B.integerDec suffix renderByteRange :: ByteRange -> B.ByteString-renderByteRange = Blaze.toByteString . renderByteRangeBuilder+renderByteRange = BL.toStrict . B.toLazyByteString . renderByteRangeBuilder -- | RFC 2616 Byte ranges (set). type ByteRanges = [ByteRange] -renderByteRangesBuilder :: ByteRanges -> Blaze.Builder-renderByteRangesBuilder xs = Blaze.copyByteString "bytes=" `mappend` - mconcat (intersperse (Blaze.fromChar ',') (map renderByteRangeBuilder xs))+renderByteRangesBuilder :: ByteRanges -> B.Builder+renderByteRangesBuilder xs = B.byteString "bytes=" `mappend`+ mconcat (intersperse (B.char7 ',') (map renderByteRangeBuilder xs)) renderByteRanges :: ByteRanges -> B.ByteString-renderByteRanges = Blaze.toByteString . renderByteRangesBuilder+renderByteRanges = BL.toStrict . B.toLazyByteString . renderByteRangesBuilder -- | Parse the value of a Range header into a 'ByteRanges'. --
Network/HTTP/Types/Status.hs view
@@ -179,9 +179,13 @@ toEnum 511 = status511 toEnum c = mkStatus c B.empty +instance Bounded Status where+ minBound = status100+ maxBound = status511+ -- | Create a Status from status code and message. mkStatus :: Int -> B.ByteString -> Status-mkStatus i m = Status i m+mkStatus = Status -- | Continue 100 status100 :: Status
Network/HTTP/Types/URI.hs view
@@ -45,8 +45,9 @@ import Data.Text.Encoding (encodeUtf8, decodeUtf8With) import Data.Text.Encoding.Error (lenientDecode) import Data.Word-import qualified Blaze.ByteString.Builder as Blaze import qualified Data.ByteString as B+import qualified Data.ByteString.Builder as B+import qualified Data.ByteString.Lazy as BL import Data.ByteString.Char8 () {-IsString-} -- | Query item@@ -65,10 +66,10 @@ queryTextToQuery :: QueryText -> Query queryTextToQuery = map $ encodeUtf8 *** fmap encodeUtf8 --- | Convert 'QueryText' to a 'Blaze.Builder'.+-- | Convert 'QueryText' to a 'B.Builder'. renderQueryText :: Bool -- ^ prepend a question mark? -> QueryText- -> Blaze.Builder+ -> B.Builder renderQueryText b = renderQueryBuilder b . queryTextToQuery -- | Convert 'Query' to 'QueryText' (leniently decoding the UTF-8).@@ -90,21 +91,21 @@ -- | Convert 'SimpleQuery' to 'Query'. simpleQueryToQuery :: SimpleQuery -> Query-simpleQueryToQuery = map (\(a, b) -> (a, Just b))+simpleQueryToQuery = map (second Just) -- | Convert 'Query' to a 'Builder'. renderQueryBuilder :: Bool -- ^ prepend a question mark? -> Query- -> Blaze.Builder+ -> B.Builder renderQueryBuilder _ [] = mempty -- FIXME replace mconcat + map with foldr renderQueryBuilder qmark' (p:ps) = mconcat $ go (if qmark' then qmark else mempty) p : map (go amp) ps where- qmark = Blaze.copyByteString "?"- amp = Blaze.copyByteString "&"- equal = Blaze.copyByteString "="+ qmark = B.byteString "?"+ amp = B.byteString "&"+ equal = B.byteString "=" go sep (k, mv) = mconcat [ sep , urlEncodeBuilder True k@@ -116,7 +117,7 @@ -- | Convert 'Query' to 'ByteString'. renderQuery :: Bool -- ^ prepend question mark? -> Query -> B.ByteString-renderQuery qm = Blaze.toByteString . renderQueryBuilder qm+renderQuery qm = BL.toStrict . B.toLazyByteString . renderQueryBuilder qm -- | Convert 'SimpleQuery' to 'ByteString'. renderSimpleQuery :: Bool -- ^ prepend question mark?@@ -174,26 +175,24 @@ unreservedPI = map ord8 "-_.~:@&=+$," -- | Percent-encoding for URLs.-urlEncodeBuilder' :: [Word8] -> B.ByteString -> Blaze.Builder+urlEncodeBuilder' :: [Word8] -> B.ByteString -> B.Builder urlEncodeBuilder' extraUnreserved = mconcat . map encodeChar . B.unpack where- encodeChar ch | unreserved ch = Blaze.fromWord8 ch+ encodeChar ch | unreserved ch = B.word8 ch | otherwise = h2 ch- + unreserved ch | ch >= 65 && ch <= 90 = True -- A-Z | ch >= 97 && ch <= 122 = True -- a-z | ch >= 48 && ch <= 57 = True -- 0-9 unreserved c = c `elem` extraUnreserved- - h2 v = let (a, b) = v `divMod` 16 in Blaze.fromWord8s [37, h a, h b] -- percent (%)- h i | i < 10 = 48 + i -- zero (0)- | otherwise = 65 + i - 10 -- 65: A --- | Percent-encoding for URLs (using 'Blaze.Builder').+ h2 v = B.word8 37 `mappend` B.word8HexFixed v -- percent (%)++-- | Percent-encoding for URLs (using 'B.Builder'). urlEncodeBuilder :: Bool -- ^ Whether input is in query string. True: Query string, False: Path element -> B.ByteString- -> Blaze.Builder+ -> B.Builder urlEncodeBuilder True = urlEncodeBuilder' unreservedQS urlEncodeBuilder False = urlEncodeBuilder' unreservedPI @@ -201,7 +200,7 @@ urlEncode :: Bool -- ^ Whether to decode '+' to ' ' -> B.ByteString -- ^ The ByteString to encode as URL -> B.ByteString -- ^ The encoded URL-urlEncode q = Blaze.toByteString . urlEncodeBuilder q+urlEncode q = BL.toStrict . B.toLazyByteString . urlEncodeBuilder q -- | Percent-decoding. urlDecode :: Bool -- ^ Whether to decode '+' to ' '@@ -254,18 +253,14 @@ -- 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.-encodePathSegments :: [Text] -> Blaze.Builder-encodePathSegments [] = mempty-encodePathSegments (x:xs) =- Blaze.copyByteString "/"- `mappend` encodePathSegment x- `mappend` encodePathSegments xs+encodePathSegments :: [Text] -> B.Builder+encodePathSegments = foldr (\x -> mappend (B.byteString "/" `mappend` encodePathSegment x)) mempty -- | Like encodePathSegments, but without the initial slash.-encodePathSegmentsRelative :: [Text] -> Blaze.Builder-encodePathSegmentsRelative xs = mconcat $ intersperse (Blaze.copyByteString "/") (map encodePathSegment xs)+encodePathSegmentsRelative :: [Text] -> B.Builder+encodePathSegmentsRelative xs = mconcat $ intersperse (B.byteString "/") (map encodePathSegment xs) -encodePathSegment :: Text -> Blaze.Builder+encodePathSegment :: Text -> B.Builder encodePathSegment = urlEncodeBuilder False . encodeUtf8 -- | Parse a list of path segments from a valid URL fragment.@@ -315,7 +310,7 @@ ensureNonEmpty p = p -- | Encode a whole path (path segments + query).-encodePath :: [Text] -> Query -> Blaze.Builder+encodePath :: [Text] -> Query -> B.Builder encodePath x [] = encodePathSegments x encodePath x y = encodePathSegments x `mappend` renderQueryBuilder True y
http-types.cabal view
@@ -1,5 +1,5 @@ Name: http-types-Version: 0.10+Version: 0.11 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.10+ tag: 0.11 Source-repository head type: git@@ -32,10 +32,9 @@ Network.HTTP.Types.Version GHC-Options: -Wall Build-depends: base >= 4 && < 5,- bytestring >=0.9.1.5 && <0.11,+ bytestring >=0.10.4.0 && <1.0, array >=0.2 && <0.6, case-insensitive >=0.2 && <1.3,- blaze-builder >= 0.2.1.4 && < 0.5, text >= 0.11.0.2 Test-suite spec@@ -47,7 +46,6 @@ http-types, text, bytestring,- blaze-builder, QuickCheck, quickcheck-instances, hspec >= 1.3