Skip to content

Commit

Permalink
Rebased for transfer of repo to byteverse.
Browse files Browse the repository at this point in the history
Reformatted code and removed workflows.
  • Loading branch information
brianjosephmckeon authored Jan 25, 2024
1 parent 4ac6f25 commit ba94fc7
Show file tree
Hide file tree
Showing 7 changed files with 451 additions and 350 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/
dist
dist-*
cabal-dev
Expand Down
51 changes: 51 additions & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Number of spaces per indentation step
indentation: 2

# Max line length for automatic line breaking
column-limit: 200

# Styling of arrows in type signatures (choices: trailing, leading, or leading-args)
function-arrows: trailing

# How to place commas in multi-line lists, records, etc. (choices: leading or trailing)
comma-style: leading

# Styling of import/export lists (choices: leading, trailing, or diff-friendly)
import-export-style: leading

# Whether to full-indent or half-indent 'where' bindings past the preceding body
indent-wheres: false

# Whether to leave a space before an opening record brace
record-brace-space: true

# Number of spaces between top-level declarations
newlines-between-decls: 1

# How to print Haddock comments (choices: single-line, multi-line, or multi-line-compact)
haddock-style: multi-line

# How to print module docstring
haddock-style-module: null

# Styling of let blocks (choices: auto, inline, newline, or mixed)
let-style: auto

# How to align the 'in' keyword with respect to the 'let' keyword (choices: left-align, right-align, or no-space)
in-style: right-align

# Whether to put parentheses around a single constraint (choices: auto, always, or never)
single-constraint-parens: always

# Output Unicode syntax (choices: detect, always, or never)
unicode: never

# Give the programmer more choice on where to insert blank lines
respectful: true

# Fixity information for operators
fixities: []

# Module reexports Fourmolu should know about
reexports: []

95 changes: 50 additions & 45 deletions http-exchange.cabal
Original file line number Diff line number Diff line change
@@ -1,67 +1,72 @@
cabal-version: 3.0
name: http-exchange
version: 0.2.0.0
synopsis: Perform HTTP Requests
description: Perform HTTP requests. This uses backpack and is agnostic to the backend.
license: BSD-3-Clause
license-file: LICENSE
author: Andrew Martin
maintainer: [email protected]
copyright: 2023 Andrew Martin
category: Data
build-type: Simple
cabal-version: 3.0
name: http-exchange
version: 0.2.0.0
synopsis: Perform HTTP Requests
description:
Perform HTTP requests. This uses backpack and is agnostic to the backend.

license: BSD-3-Clause
license-file: LICENSE
author: Andrew Martin
maintainer: [email protected]
copyright: 2023 Andrew Martin
category: Data
build-type: Simple
extra-doc-files: CHANGELOG.md

library types
ghc-options: -Wall
exposed-modules: Http.Exchange.Types
ghc-options: -Wall
exposed-modules: Http.Exchange.Types
build-depends:
, base >=4.16.3.0 && <5
, byteslice >=0.2.11.1
hs-source-dirs: src-types
, base >=4.16.3.0 && <5
, byteslice >=0.2.11.1

hs-source-dirs: src-types
default-language: GHC2021

library testdep
ghc-options: -Wall
exposed-modules: OkChannel
ghc-options: -Wall
exposed-modules: OkChannel
build-depends:
, base >=4.16.3.0 && <5
, byteslice >=0.2.11
, base >=4.16.3.0 && <5
, byteslice >=0.2.11
, types
hs-source-dirs: src-testdep

hs-source-dirs: src-testdep
default-language: GHC2021

library
signatures: Channel
ghc-options: -Wall
exposed-modules: Exchange
signatures: Channel
ghc-options: -Wall
exposed-modules: Exchange
build-depends:
, base >=4.16.3.0 && <5
, http-interchange >=0.3.1
, text >= 2.0
, base >=4.16.3.0 && <5
, byteslice >=0.2.11
, bytesmith >=0.3.9
, http-interchange >=0.3.1
, primitive >=0.8
, text >=2.0
, types
, primitive >=0.8
, byteslice >=0.2.11
, bytesmith >=0.3.9
hs-source-dirs: src

hs-source-dirs: src
default-language: GHC2021

test-suite test
ghc-options: -Wall
ghc-options: -Wall
default-language: GHC2021
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Main.hs
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Main.hs
build-depends:
, base >=4.16.3.0 && <5
, http-interchange >=0.3.1
, base >=4.16.3.0 && <5
, byteslice
, bytestring >=0.11
, http-exchange
, http-interchange >=0.3.1
, primitive >=0.8
, tasty >=1.4.3
, tasty-hunit >=0.10.0.3
, testdep
, tasty >=1.4.3
, tasty-hunit >=0.10.0.3
, byteslice
, bytestring >=0.11
, primitive >=0.8

mixins:
http-exchange (Exchange as OkExchange)
requires (Channel as OkChannel)
http-exchange (Exchange as OkExchange) requires (Channel as OkChannel)
40 changes: 20 additions & 20 deletions src-testdep/OkChannel.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{-# language DeriveFunctor #-}
{-# language DerivingStrategies #-}
{-# language KindSignatures #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE KindSignatures #-}

module OkChannel
( M(..)
, ReceiveException(..)
( M (..)
, ReceiveException (..)
, SendException
, showsPrecReceiveException
, showsPrecSendException
Expand All @@ -14,11 +14,11 @@ module OkChannel
) where

import Data.Bytes (Bytes)
import Data.Bytes.Chunks (Chunks(ChunksNil,ChunksCons))
import Data.Void (Void,absurd)
import Data.Bytes.Chunks (Chunks (ChunksCons, ChunksNil))
import Data.Void (Void, absurd)

import qualified Data.Bytes as Bytes
import qualified Data.Bytes.Chunks as Chunks
import Data.Bytes qualified as Bytes
import Data.Bytes.Chunks qualified as Chunks

type Resource = ()

Expand All @@ -37,18 +37,18 @@ showsPrecSendException _ x _ = absurd x
-- The input is peeled off one byte sequence at a time by receive
-- We use this feature to feed input byte-by-byte to test streaming
-- features.
data M a = M (Chunks -> Bytes -> (Chunks,Bytes,a))
data M a = M (Chunks -> Bytes -> (Chunks, Bytes, a))
deriving stock (Functor)

bindM :: M a -> (a -> M b) -> M b
bindM (M f) g = M $ \inbound0 outbound0 ->
case f inbound0 outbound0 of
(inbound1,outbound1,a) ->
(inbound1, outbound1, a) ->
case g a of
M h -> h inbound1 outbound1

pureM :: a -> M a
pureM a = M $ \x y -> (x,y,a)
pureM a = M $ \x y -> (x, y, a)

instance Applicative M where
pure = pureM
Expand All @@ -58,19 +58,19 @@ instance Monad M where
(>>=) = bindM

send ::
()
-> Chunks
-> M (Either SendException ())
() ->
Chunks ->
M (Either SendException ())
send _ b = M $ \inbound outbound ->
(inbound,outbound <> Chunks.concat b,Right ())
(inbound, outbound <> Chunks.concat b, Right ())

receive ::
()
-> M (Either ReceiveException Bytes)
() ->
M (Either ReceiveException Bytes)
receive _ = M $ \inbound0 outbound ->
let go inbound = case inbound of
ChunksNil -> (inbound,outbound,Left ExpectedMoreInput)
ChunksNil -> (inbound, outbound, Left ExpectedMoreInput)
ChunksCons b ch -> case Bytes.null b of
True -> go ch
False -> (ch,outbound,Right b)
False -> (ch, outbound, Right b)
in go inbound0
27 changes: 14 additions & 13 deletions src-types/Http/Exchange/Types.hs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{-# language DeriveAnyClass #-}
{-# language DerivingStrategies #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}

module Http.Exchange.Types
( HttpException(..)
( HttpException (..)
) where

import Control.Exception qualified as E
import Data.Bytes (Bytes)
import qualified Control.Exception as E

-- | Exceptions that occur when decoding an HTTP response.
-- If this happens, the only way to proceed is to
-- shut down the connection. Either the server does not
-- speak HTTP correct, or there is a mistake in this libary.
{- | Exceptions that occur when decoding an HTTP response.
If this happens, the only way to proceed is to
shut down the connection. Either the server does not
speak HTTP correct, or there is a mistake in this libary.
-}
data HttpException
= ChunkTooLarge
| ChunkedBodyEndOfInput
Expand All @@ -23,13 +24,13 @@ data HttpException
| ExpectedCrlfAfterChunkLength
| ExpectedCrlfBeforeChunkLength
| HeadersMalformed
| HeadersEndOfInput
| -- | The entire contents of the response.
HeadersEndOfInput
{-# UNPACK #-} !Bytes
-- ^ The entire contents of the response.
| HeadersTooLarge
| ImplementationMistake
-- ^ If this one happens, there is a mistake in this
| -- | If this one happens, there is a mistake in this
-- library.
ImplementationMistake
| NonNumericChunkLength
| PipelinedResponses
| TransferEncodingUnrecognized
Expand All @@ -47,7 +48,7 @@ instance Show HttpException where
showsPrec _ ExpectedCrlfAfterChunkLength = showString "ExpectedCrlfAfterChunkLength"
showsPrec _ ExpectedCrlfBeforeChunkLength = showString "ExpectedCrlfBeforeChunkLength"
showsPrec _ HeadersMalformed = showString "HeadersMalformed"
showsPrec _ HeadersEndOfInput{} = showString "HeadersEndOfInput{..}"
showsPrec _ HeadersEndOfInput {} = showString "HeadersEndOfInput{..}"
showsPrec _ HeadersTooLarge = showString "HeadersTooLarge"
showsPrec _ ImplementationMistake = showString "ImplementationMistake"
showsPrec _ NonNumericChunkLength = showString "NonNumericChunkLength"
Expand Down
Loading

0 comments on commit ba94fc7

Please sign in to comment.