Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup. #3

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for http-interchange

## 0.3.2.0 -- 2024-01-16

* Add `Eq` and `Show` to all data types.

## 0.3.1.0 -- 2023-08-16

* Add these to `Http.Headers`: cons, snoc, lookupHost, lookupAccept,
Expand Down
2 changes: 1 addition & 1 deletion http-interchange.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: http-interchange
version: 0.3.1.0
version: 0.3.2.0
brianjosephmckeon marked this conversation as resolved.
Show resolved Hide resolved
license: BSD-3-Clause
license-file: LICENSE
author: Andrew Martin
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Bodied.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ data Bodied a = Bodied
, body :: !Chunks
-- ^ The body.
}
deriving (Show, Eq)
deriving (Eq, Show)
4 changes: 1 addition & 3 deletions src/Http/Header.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ module Http.Header
, builderSmallArray
) where

import Control.Monad (when)
import Data.Bytes (Bytes)
import Data.Bytes.Builder (Builder)
import Data.Bytes.Parser (Parser)
import Data.Bytes.Types (Bytes (Bytes))
import Data.Primitive (ByteArray (ByteArray), SmallArray, SmallMutableArray)
import Data.Text (Text)
import Data.Word (Word16, Word8)

import Data.Bytes qualified as Bytes
import Data.Bytes.Builder qualified as Builder
Expand All @@ -35,7 +33,7 @@ data Header = Header
{ name :: {-# UNPACK #-} !Text
, value :: {-# UNPACK #-} !Text
}
deriving (Show)
deriving (Eq, Show)

uninitializedHeader :: Header
{-# NOINLINE uninitializedHeader #-}
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Headers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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, Semigroup, Monoid)
deriving newtype (Eq, 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
Expand All @@ -78,6 +78,7 @@ lookup failure was the result of something that might be expected
data LookupException
= Duplicate
| Missing
deriving (Eq, Show)

{- | Convert array of headers to a 'Headers' collection that supports
efficient lookup.
Expand Down
10 changes: 3 additions & 7 deletions src/Http/Request.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MagicHash #-}

module Http.Request
Expand All @@ -17,12 +16,9 @@ module Http.Request

import Data.Bytes.Builder (Builder)
import Data.Bytes.Chunks (Chunks)
import Data.Primitive (SmallArray)
import Data.Text (Text)
import Data.Word (Word8)
import GHC.Exts (Ptr (Ptr))
import Http.Bodied (Bodied (..))
import Http.Header (Header)
import Http.Headers (Headers)

import Data.Bytes.Builder qualified as Builder
Expand All @@ -36,14 +32,14 @@ data Request = Request
{ requestLine :: !RequestLine
, headers :: !Headers
}
deriving (Show)
deriving (Eq, Show)

-- | An HTTP request line
data RequestLine = RequestLine
{ method :: {-# UNPACK #-} !Text
, path :: {-# UNPACK #-} !Text
}
deriving (Show)
deriving (Eq, Show)

builderRequestLine :: RequestLine -> Builder
builderRequestLine RequestLine {method, path} =
Expand All @@ -57,7 +53,7 @@ toChunks :: Request -> Chunks
toChunks = Builder.run 256 . builder

toChunksOnto :: Request -> Chunks -> Chunks
toChunksOnto r ch = Builder.runOnto 256 (builder r) ch
toChunksOnto r = Builder.runOnto 256 (builder r)

builder :: Request -> Builder
builder Request {requestLine, headers} =
Expand Down
10 changes: 4 additions & 6 deletions src/Http/Response.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}

module Http.Response
( Response (..)
Expand All @@ -11,10 +10,9 @@ import Control.Monad (when)
import Data.Bytes (Bytes)
import Data.Bytes.Parser (Parser)
import Data.Bytes.Types (Bytes (Bytes))
import Data.Primitive (ByteArray (ByteArray), SmallArray)
import Data.Primitive (ByteArray (ByteArray))
import Data.Text (Text)
import Data.Word (Word16, Word8)
import Http.Header (Header)
import Data.Word (Word16)
import Http.Headers (Headers)

import Data.Bytes.Parser qualified as Parser
Expand All @@ -29,13 +27,13 @@ data Response = Response
{ statusLine :: !StatusLine
, headers :: !Headers
}
deriving (Show)
deriving (Eq, Show)

data StatusLine = StatusLine
{ statusCode :: !Word16
, statusReason :: {-# UNPACK #-} !Text
}
deriving (Show)
deriving (Eq, Show)

{- | Decode the response status line and the response headers. Fails if
any extraneous input is present after the double CRLF sequence that
Expand Down