Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 31 additions & 0 deletions .github/workflows/include.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Same as full workflow (eg from fortio/gvi) but without the goreleaser step
name: "shared fortio workflows"

on:
push:
branches: [ main ] # put back once testing with pre-releases on branch is done.
tags:
- 'v*'
pull_request:
branches: [ main ]

jobs:
call-gochecks:
uses: fortio/workflows/.github/workflows/gochecks.yml@main
# call-codecov:
# uses: fortio/workflows/.github/workflows/codecov.yml@main
# secrets:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
call-codeql:
uses: fortio/workflows/.github/workflows/codeql-analysis.yml@main
releaser-h2cli:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
uses: fortio/workflows/.github/workflows/releaser.yml@main
with:
description: "Simple http 2.0 (h2 and h2c) client in go, including streaming"
binary_name: "h2cli"
dockerfile: "./Dockerfile"
secrets:
GH_PAT: ${{ secrets.GH_PAT }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
DOCKER_USER: ${{ secrets.DOCKER_USER }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

# Dependency directories (remove the comment below to include it)
# vendor/
.golangci.yml
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM scratch
COPY h2cli /usr/bin/h2cli
ENV HOME=/home/user
ENTRYPOINT ["/usr/bin/h2cli"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Simple http 2.0 (h2) client in go including h2c (http2 over clear text, not requ
go install github.com/fortio/h2cli@latest
```

or see the binary releases.

## Running

Options/flags:
Expand Down
9 changes: 6 additions & 3 deletions h2cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ func main() {
AllowHTTP: true, // to get h2c
// Trick to get h2c without TLS:
// thanks to https://github.com/thrawn01/h2c-golang-example/blob/master/README.md
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
return net.Dial(network, addr)
DialTLSContext: func(ctx context.Context, network, addr string, _ *tls.Config) (net.Conn, error) {
var d net.Dialer
return d.DialContext(ctx, network, addr)
},
}
}
Expand All @@ -87,12 +88,14 @@ func main() {
if err != nil {
log.Fatalf("Request method %q url %q error: %v", *method, *urlFlag, err)
}
//nolint:gosec // yes we want to fetch the url given as input.
resp, err := client.Do(req)
if err != nil {
log.Fatalf("Failed %q %q - error: %v", *method, *urlFlag, err)
}
if *stream {
n, err := io.Copy(os.Stdout, resp.Body)
var n int64
n, err = io.Copy(os.Stdout, resp.Body)
log.Infof("Response code %d, proto %s, size %d", resp.StatusCode, resp.Proto, n)
if err != nil {
log.Fatalf("Error copying response body: %v", err)
Expand Down