-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebased for transfer of repo to byteverse.
Reformatted code and removed workflows.
- Loading branch information
1 parent
cc2fb67
commit 3a0ea96
Showing
10 changed files
with
429 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.vscode/ | ||
dist | ||
dist-* | ||
cabal-dev | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.