packages feed

http-interchange 0.2.0.0 → 0.3.0.0

raw patch · 6 files changed

+24/−17 lines, 6 filesdep ~basedep ~contiguous

Dependency ranges changed: base, contiguous

Files

CHANGELOG.md view
@@ -1,5 +1,13 @@ # Revision history for http-interchange +## 0.3.0.0 -- 2023-08-15++* Add `Http.Headers.fromList`. In examples, this makes it easier+  to create HTTP requests.+* Add `Eq` and `Show` instances for `Bodied`.+* Get rid of `versionMajor` and `versionMinor` from both requests+  and responses. Only support HTTP/1.1.+ ## 0.2.0.0 -- 2023-08-14  * Redo module structure
http-interchange.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: http-interchange-version: 0.2.0.0+version: 0.3.0.0 license: BSD-3-Clause license-file: LICENSE author: Andrew Martin@@ -25,7 +25,7 @@     Http.Headers     Http.Types   build-depends:-    , base >=4.16.4.0 && <5+    , base >=4.16.3.0 && <5     , bytesmith >=0.3.10     , byteslice >=0.2.11     , primitive >=0.7.4
src/Http/Bodied.hs view
@@ -10,4 +10,4 @@     -- ^ The request or response.   , body :: !Chunks     -- ^ The body.-  }+  } deriving (Show,Eq)
src/Http/Headers.hs view
@@ -12,6 +12,7 @@   , LookupException(..)     -- * Construct   , fromArray+  , fromList     -- * Expose   , toArray     -- * Lookup@@ -35,6 +36,7 @@ import qualified Data.Primitive.Contiguous as C import qualified Data.Text as T import qualified Http.Header+import qualified GHC.Exts as Exts  -- | Collection of HTTP headers. Supports case-insensitive lookup. -- This is intended to be used for small collections of headers.@@ -59,6 +61,11 @@ -- efficient lookup. fromArray :: SmallArray Header -> Headers fromArray = Headers++-- | Convert list of headers to a 'Headers' collection that supports+-- efficient lookup.+fromList :: [Header] -> Headers+fromList = Headers . Exts.fromList  -- | Recover the original headers from from the 'Headers' collection. -- This is @O(1)@ and is most commonly used to fold over the headers.
src/Http/Request.hs view
@@ -39,12 +39,10 @@ data RequestLine = RequestLine   { method :: {-# UNPACK #-} !Text   , path :: {-# UNPACK #-} !Text-  , versionMajor :: !Word8-  , versionMinor :: !Word8   } deriving (Show)  builderRequestLine :: RequestLine -> Builder-builderRequestLine RequestLine{method,path,versionMajor,versionMinor} =+builderRequestLine RequestLine{method,path} =   Builder.copy (Utf8.fromText method)   <>   Builder.ascii ' '@@ -53,13 +51,7 @@   <>   Builder.ascii6 ' ' 'H' 'T' 'T' 'P' '/'   <>-  Builder.word8Dec versionMajor-  <>-  Builder.ascii '.'-  <>-  Builder.word8Dec versionMinor-  <>-  Builder.ascii2 '\r' '\n'+  Builder.ascii5 '1' '.' '1' '\r' '\n'  toChunks :: Request -> Chunks toChunks = Builder.run 256 . builder
src/Http/Response.hs view
@@ -31,9 +31,7 @@   } deriving (Show)  data StatusLine = StatusLine-  { versionMajor :: !Word8-  , versionMinor :: !Word8-  , statusCode :: !Word16+  { statusCode :: !Word16   , statusReason :: {-# UNPACK #-} !Text   } deriving (Show) @@ -58,8 +56,10 @@ parserStatusLine = do   Latin.char5 () 'H' 'T' 'T' 'P' '/'   versionMajor <- Latin.decWord8 ()+  when (versionMajor /= 1) (Parser.fail ())   Latin.char () '.'   versionMinor <- Latin.decWord8 ()+  when (versionMinor /= 1) (Parser.fail ())   Latin.char () ' '   statusCode <- Latin.decWord16 ()   when (statusCode >= 1000) (Parser.fail ())@@ -70,7 +70,7 @@     ||     (c == 0x09)   Latin.char2 () '\r' '\n'-  pure StatusLine{versionMajor,versionMinor,statusCode,statusReason=unsafeBytesToText statusReason}+  pure StatusLine{statusCode,statusReason=unsafeBytesToText statusReason}  unsafeBytesToText :: Bytes -> Text {-# inline unsafeBytesToText #-}