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 cc2fb67 commit 3a0ea96
Show file tree
Hide file tree
Showing 10 changed files with 429 additions and 322 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
44 changes: 25 additions & 19 deletions app-http-insecure/Main.hs
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
{-# language OverloadedStrings #-}
{-# LANGUAGE OverloadedStrings #-}

import Control.Exception (bracket,throwIO)
import Control.Exception (bracket, throwIO)
import Http.Exchange.Network (exchange)
import Http.Types (Request(..),RequestLine(..),Bodied(..),Header(Header))
import Http.Headers qualified as Headers
import Http.Types (Bodied (..), Header (Header), Request (..), RequestLine (..))
import Network.Socket qualified as N
import Text.Show.Pretty (pPrint)
import qualified Http.Headers as Headers
import qualified Network.Socket as N

main :: IO ()
main = do
let hints = N.defaultHints { N.addrSocketType = N.Stream }
let hints = N.defaultHints {N.addrSocketType = N.Stream}
minfo <- N.getAddrInfo (Just hints) (Just "ifconfig.me") (Just "80")
info <- case minfo of
info : _ -> pure info
[] -> fail "Impossible: getAddrInfo cannot return empty list"
bracket (N.openSocket info) N.close $ \sock -> do
N.connect sock (N.addrAddress info)
result <- exchange sock Bodied
{ metadata = Request
{ requestLine = RequestLine
{ method = "GET"
, path = "/ip"
result <-
exchange
sock
Bodied
{ metadata =
Request
{ requestLine =
RequestLine
{ method = "GET"
, path = "/ip"
}
, headers =
Headers.fromList
[ Header "Host" "ifconfig.me"
, Header "Accept" "text/plain"
, Header "User-Agent" "curl/0.0.0"
]
}
, body = mempty
}
, headers = Headers.fromList
[ Header "Host" "ifconfig.me"
, Header "Accept" "text/plain"
, Header "User-Agent" "curl/0.0.0"
]
}
, body = mempty
}
case result of
Left e -> throwIO e
Right resp -> pPrint resp
91 changes: 50 additions & 41 deletions app-http-secure/Main.hs
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
{-# language OverloadedStrings #-}
{-# LANGUAGE OverloadedStrings #-}

import Control.Exception (bracket,throwIO)
import Http.Exchange.Tls (SocketThrowingNetworkException(..),exchange)
import Http.Types (Request(..),RequestLine(..),Bodied(..),Header(Header))
import Text.Show.Pretty (pPrint)
import Control.Exception (bracket, throwIO)
import Data.Default (def)
import qualified Http.Headers as Headers
import qualified Network.Socket as N
import qualified Network.TLS.Extra.Cipher as Tls
import qualified Network.TLS as Tls
import Http.Exchange.Tls (SocketThrowingNetworkException (..), exchange)
import Http.Headers qualified as Headers
import Http.Types (Bodied (..), Header (Header), Request (..), RequestLine (..))
import Network.Socket qualified as N
import Network.TLS qualified as Tls
import Network.TLS.Extra.Cipher qualified as Tls
import Text.Show.Pretty (pPrint)

main :: IO ()
main = do
let noValidation = Tls.ValidationCache
(\_ _ _ -> return Tls.ValidationCachePass)
(\_ _ _ -> return ())
let clientParams = (Tls.defaultParamsClient "ifconfig.me" mempty)
{ Tls.clientSupported = def
{ Tls.supportedVersions = [Tls.TLS13]
, Tls.supportedCiphers =
[ Tls.cipher_TLS13_AES128GCM_SHA256
, Tls.cipher_TLS13_AES256GCM_SHA384
, Tls.cipher_TLS13_CHACHA20POLY1305_SHA256
, Tls.cipher_TLS13_AES128CCM_SHA256
, Tls.cipher_TLS13_AES128CCM8_SHA256
]
let noValidation =
Tls.ValidationCache
(\_ _ _ -> return Tls.ValidationCachePass)
(\_ _ _ -> return ())
let clientParams =
(Tls.defaultParamsClient "ifconfig.me" mempty)
{ Tls.clientSupported =
def
{ Tls.supportedVersions = [Tls.TLS13]
, Tls.supportedCiphers =
[ Tls.cipher_TLS13_AES128GCM_SHA256
, Tls.cipher_TLS13_AES256GCM_SHA384
, Tls.cipher_TLS13_CHACHA20POLY1305_SHA256
, Tls.cipher_TLS13_AES128CCM_SHA256
, Tls.cipher_TLS13_AES128CCM8_SHA256
]
}
, Tls.clientShared =
def
{ Tls.sharedValidationCache = noValidation
}
}
, Tls.clientShared = def
{ Tls.sharedValidationCache = noValidation
}
}
let hints = N.defaultHints { N.addrSocketType = N.Stream }
let hints = N.defaultHints {N.addrSocketType = N.Stream}
minfo <- N.getAddrInfo (Just hints) (Just "ifconfig.me") (Just "443")
info <- case minfo of
info : _ -> pure info
Expand All @@ -39,21 +43,26 @@ main = do
N.connect sock (N.addrAddress info)
ctx <- Tls.contextNew (SocketThrowingNetworkException sock) clientParams
Tls.handshake ctx
result <- exchange ctx Bodied
{ metadata = Request
{ requestLine = RequestLine
{ method = "GET"
, path = "/ip"
result <-
exchange
ctx
Bodied
{ metadata =
Request
{ requestLine =
RequestLine
{ method = "GET"
, path = "/ip"
}
, headers =
Headers.fromList
[ Header "Host" "ifconfig.me"
, Header "Accept" "text/plain"
, Header "User-Agent" "curl/0.0.0"
]
}
, body = mempty
}
, headers = Headers.fromList
[ Header "Host" "ifconfig.me"
, Header "Accept" "text/plain"
, Header "User-Agent" "curl/0.0.0"
]
}
, body = mempty
}
case result of
Left e -> throwIO e
Right resp -> pPrint resp

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: []

112 changes: 58 additions & 54 deletions http-exchange-instantiations.cabal
Original file line number Diff line number Diff line change
@@ -1,83 +1,87 @@
cabal-version: 3.0
name: http-exchange-instantiations
version: 0.1.3.0
synopsis: Instantiations of http-exchange
cabal-version: 3.0
name: http-exchange-instantiations
version: 0.1.3.0
synopsis: Instantiations of http-exchange

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

library chanimpl
ghc-options: -Wall
ghc-options: -Wall
exposed-modules:
SocketChannel
SocketInterruptibleChannel
TlsChannel
-- TlsInterruptibleChannel

-- TlsInterruptibleChannel
build-depends:
, base >=4.16.3.0 && <5
, network-unexceptional >=0.2
, network >=3.1.4
, tls >=1.8
, error-codes >=0.1.1
, bytestring >=0.11
, byteslice >=0.2.11
, stm >=2.5.1.0
hs-source-dirs: src-chanimpl
, base >=4.16.3.0 && <5
, byteslice >=0.2.11
, bytestring >=0.11
, error-codes >=0.1.1
, network >=3.1.4
, network-unexceptional >=0.2
, stm >=2.5.1.0
, tls >=1.8

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

library
ghc-options: -Wall
ghc-options: -Wall
exposed-modules:
Http.Exchange.Network
Http.Exchange.Tls

build-depends:
, base >=4.16.3.0
, base >=4.16.3.0
, bytestring >=0.11
, chanimpl
, http-exchange >=0.1.1
, http-interchange >=0.3.1
, network >=3.1.4
, stm >=2.5.1.0
, tls >=1.7
, network-unexceptional >=0.2
, bytestring >=0.11
hs-source-dirs: src
, http-exchange >=0.1.1
, http-interchange >=0.3.1
, network >=3.1.4
, network-unexceptional >=0.2
, stm >=2.5.1.0
, tls >=1.7

hs-source-dirs: src
default-language: GHC2021
mixins:
http-exchange (Exchange as SocketExchange)
requires (Channel as SocketChannel),
http-exchange (Exchange as TlsExchange)
requires (Channel as TlsChannel),
http-exchange (Exchange as SocketInterruptibleExchange)
requires (Channel as SocketInterruptibleChannel)
http-exchange (Exchange as SocketExchange) requires (Channel as SocketChannel),
http-exchange (Exchange as TlsExchange) requires (Channel as TlsChannel),
http-exchange (Exchange as SocketInterruptibleExchange) requires (Channel as SocketInterruptibleChannel)

executable http-insecure
ghc-options: -Wall
main-is: Main.hs
ghc-options: -Wall
main-is: Main.hs
build-depends:
, base >=4.16.3.0
, network >=3.1.4
, http-interchange >=0.3.1
, base >=4.16.3.0
, http-exchange-instantiations
, pretty-show >=1.10
hs-source-dirs: app-http-insecure
, http-interchange >=0.3.1
, network >=3.1.4
, pretty-show >=1.10

hs-source-dirs: app-http-insecure
default-language: GHC2021

executable http-secure
ghc-options: -Wall
main-is: Main.hs
ghc-options: -Wall
main-is: Main.hs
build-depends:
, base >=4.16.3.0
, network >=3.1.4
, http-interchange >=0.3.1
, base >=4.16.3.0
, data-default >=0.7.1
, http-exchange-instantiations
, pretty-show >=1.10
, tls >=1.7
, data-default >=0.7.1
hs-source-dirs: app-http-secure
, http-interchange >=0.3.1
, network >=3.1.4
, pretty-show >=1.10
, tls >=1.7

hs-source-dirs: app-http-secure
default-language: GHC2021
Loading

0 comments on commit 3a0ea96

Please sign in to comment.