http-interchange 0.3.0.0 → 0.3.1.0
raw patch · 3 files changed
+52/−6 lines, 3 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Http.Headers: cons :: Header -> Headers -> Headers
+ Http.Headers: instance GHC.Base.Monoid Http.Headers.Headers
+ Http.Headers: instance GHC.Base.Semigroup Http.Headers.Headers
+ Http.Headers: lacksContentLengthAndTransferEncoding :: Headers -> Bool
+ Http.Headers: lookupAccept :: Headers -> Either LookupException Header
+ Http.Headers: lookupDate :: Headers -> Either LookupException Header
+ Http.Headers: lookupHost :: Headers -> Either LookupException Header
+ Http.Headers: snoc :: Headers -> Header -> Headers
+ Http.Headers: snocContentLength :: Headers -> Text -> Headers
Files
- CHANGELOG.md +6/−0
- http-interchange.cabal +2/−2
- src/Http/Headers.hs +44/−4
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for http-interchange +## 0.3.1.0 -- 2023-08-16++* Add these to `Http.Headers`: cons, snoc, lookupHost, lookupAccept,+ lookupDate, lacksContentLengthAndTransferEncoding,+ snocContentLength.+ ## 0.3.0.0 -- 2023-08-15 * Add `Http.Headers.fromList`. In examples, this makes it easier
http-interchange.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: http-interchange-version: 0.3.0.0+version: 0.3.1.0 license: BSD-3-Clause license-file: LICENSE author: Andrew Martin@@ -31,7 +31,7 @@ , primitive >=0.7.4 , text >=2.0 , bytebuild >=0.3.10- , contiguous >=0.6.4+ , contiguous >=0.6.3 hs-source-dirs: src default-language: GHC2021
src/Http/Headers.hs view
@@ -13,6 +13,9 @@ -- * Construct , fromArray , fromList+ -- * Modify+ , cons+ , snoc -- * Expose , toArray -- * Lookup@@ -23,20 +26,29 @@ , lookupContentType , lookupContentLength , lookupTransferEncoding+ , lookupHost+ , lookupAccept+ , lookupDate+ -- * Specialized Snoc+ , snocContentLength+ -- * Specialized Absence+ , lacksContentLengthAndTransferEncoding ) where import Prelude hiding (lookup) -import Data.Text (Text)+import Data.Foldable (foldl')+import Data.Maybe (isNothing) import Data.Primitive (SmallArray)+import Data.Text (Text) import Http.Header (Header(Header))-import Data.Foldable (foldl') import qualified Data.List as List+import qualified Data.Primitive as PM import qualified Data.Primitive.Contiguous as C import qualified Data.Text as T-import qualified Http.Header import qualified GHC.Exts as Exts+import qualified Http.Header -- | Collection of HTTP headers. Supports case-insensitive lookup. -- This is intended to be used for small collections of headers.@@ -46,7 +58,7 @@ -- This preserves the original order of the headers and the original -- case of the header names. newtype Headers = Headers (SmallArray Header)- deriving newtype (Show)+ deriving newtype (Show,Semigroup,Monoid) -- | Many headers cannot appear more than once. This is part of -- the return type for 'lookup', and it helps us track whether the@@ -62,6 +74,14 @@ fromArray :: SmallArray Header -> Headers fromArray = Headers +-- | Add a header to the beginning of the headers.+cons :: Header -> Headers -> Headers+cons hdr (Headers hdrs) = Headers (C.insertAt hdrs 0 hdr)++-- | Add a header to the beginning of the headers.+snoc :: Headers -> Header -> Headers+snoc (Headers hdrs) hdr = Headers (C.insertAt hdrs (PM.sizeofSmallArray hdrs) hdr)+ -- | Convert list of headers to a 'Headers' collection that supports -- efficient lookup. fromList :: [Header] -> Headers@@ -123,3 +143,23 @@ lookupContentLength :: Headers -> Either LookupException Header lookupContentLength = lookup "content-length"++lookupHost :: Headers -> Either LookupException Header+lookupHost = lookup "host"++lookupAccept :: Headers -> Either LookupException Header+lookupAccept = lookup "accept"++lookupDate :: Headers -> Either LookupException Header+lookupDate = lookup "date"++snocContentLength :: Headers -> Text -> Headers+snocContentLength hdrs val = snoc hdrs (Header "Content-Length" val)++-- | Returns @True@ if both the @Content-Length@ and @Transfer-Encoding@+-- headers are missing.+lacksContentLengthAndTransferEncoding :: Headers -> Bool+lacksContentLengthAndTransferEncoding hdrs =+ isNothing (lookupFirst "content-length" hdrs)+ &&+ isNothing (lookupFirst "transfer-encoding" hdrs)