- Go 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
Suite release / finalize (push) Has been skipped
Suite release / scope (push) Successful in 14s
Suite release / check-build (none, ubuntu-latest) (ubuntu-latest, none) (push) Has been skipped
Suite release / build (none, ubuntu-latest) (ubuntu-latest, none) (push) Has been skipped
Suite release / reused-checks (push) Has been skipped
Suite release / deliver (push) Has been skipped
Suite release / deploy-image (push) Has been skipped
Suite release / check-package (push) Has been skipped
Suite release / deliver-prune (push) Has been skipped
Suite release / reserve (push) Has been skipped
Suite release / publish (push) Has been skipped
Suite release / module (push) Successful in 29s
|
||
| go.mod | ||
| netclient.go | ||
| netclient_test.go | ||
| README.md | ||
netclient
The HTTP client every home tool uses for calls that leave the machine, built for slow, lossy links (hotel Wi-Fi: a quarter-second round trip and a third of packets lost, with the tunnel home still working). A fixed total timeout fails a transfer that was still moving, and an agent then reads "the network is down"; this client fails only a transfer that has stopped.
- No total-duration cap. Connecting (dial and TLS) is bounded by
Dial, the wait for response headers byHeaders, and a body byIdle: a body fails only onceIdlepasses with no bytes arriving. - Transient failures (failing to connect, timeouts, resets, a stalled body, 502/503/504)
are retried with a doubling, jittered pause up to
MaxPause, untilGiveUppasses with no progress; the error then names the host and how long it tried. - Only a request that is safe to send again is retried: GET, HEAD, OPTIONS, TRACE, PUT and
DELETE, or one marked
Idempotent. Any request is retried when it failed before a connection was made.NoReplaylimits a request to that case. - A GET whose body breaks part-way resumes with a Range request when the server offers ranges.
- Each retry writes one line, to stderr or the tool's
Log:slow link to <host>: <error>, retrying (n) in <pause>.
It was agent-tools' netclient package until shared packages got repositories of their own
(AGT-85,
AHT-258).
Using it
require forgejo.romaine.life/romaine-life/netclient v0.1.1
import "forgejo.romaine.life/romaine-life/netclient"
resp, err := netclient.Client().Get(url) // the shared client, retries to stderr
c := netclient.New(netclient.Options{Log: logLine}) // a background tool's own log
Testing
go test ./.... The tests run against httptest servers and a fake clock, so they need no
network.
Shipping
A library: the release-module topic in
pipeline-templates' fleet.json
tags each merge that changes the code, and every fleet repository whose go.mod requires it
gets a take-up. Forgejo pushes it to its public GitHub copy, which proxy.golang.org serves
to builds outside CI.