Skip to content

Commit

Permalink
Reformatted.
Browse files Browse the repository at this point in the history
Added workflows.
  • Loading branch information
brianjosephmckeon committed Jan 18, 2024
1 parent 4ac6f25 commit c8f652d
Show file tree
Hide file tree
Showing 10 changed files with 475 additions and 361 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build-arm64-main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: main arm64

on:
push:
branches:
- main

workflow_dispatch:
branches:
- main

jobs:
call-workflow:
uses: layer-3-communications/.github/.github/workflows/build-haskell.yaml@main
with:
build-arch: arm64
slack-name: ${{ github.ref_name }}
secrets: inherit
14 changes: 14 additions & 0 deletions .github/workflows/build-arm64-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pull request arm64

on:
pull_request:
branches:
- "*"

jobs:
call-workflow:
uses: layer-3-communications/.github/.github/workflows/build-haskell.yaml@main
with:
build-arch: arm64
slack-name: ${{ github.event.pull_request.head.ref }}
secrets: inherit
18 changes: 18 additions & 0 deletions .github/workflows/build-x64-main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: main x64

on:
push:
branches:
- main

workflow_dispatch:
branches:
- main

jobs:
call-workflow:
uses: layer-3-communications/.github/.github/workflows/build-haskell.yaml@main
with:
build-arch: x64
slack-name: ${{ github.ref_name }}
secrets: inherit
14 changes: 14 additions & 0 deletions .github/workflows/build-x64-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pull request x64

on:
pull_request:
branches:
- "*"

jobs:
call-workflow:
uses: layer-3-communications/.github/.github/workflows/build-haskell.yaml@main
with:
build-arch: x64
slack-name: ${{ github.event.pull_request.head.ref }}
secrets: inherit
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
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)
56 changes: 28 additions & 28 deletions src-testdep/OkChannel.hs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{-# language DeriveFunctor #-}
{-# language DerivingStrategies #-}
{-# language KindSignatures #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE KindSignatures #-}

module OkChannel
( M(..)
, ReceiveException(..)
, SendException
, showsPrecReceiveException
, showsPrecSendException
, Resource
, send
, receive
) where
module OkChannel (
M (..),
ReceiveException (..),
SendException,
showsPrecReceiveException,
showsPrecSendException,
Resource,
send,
receive,
) 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
29 changes: 15 additions & 14 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(..)
) where
module Http.Exchange.Types (
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 Down
Loading

0 comments on commit c8f652d

Please sign in to comment.