Skip to content

v2.0.1

Latest

Choose a tag to compare

@github-actions github-actions released this 17 Sep 18:38

This is the first published release of hargo v2. The v2.0.0 tag exists and is
installable, but its release job did not run, so this page covers both.

Install

go install github.com/mrichman/hargo/v2/cmd/hargo@v2.0.1

As a library:

go get github.com/mrichman/hargo/v2

Prebuilt binaries for macOS, Linux, Windows, FreeBSD, NetBSD, and OpenBSD are
attached below, covering amd64, arm64, 386, and armv7 where each platform
supports them.

The module path is now github.com/mrichman/hargo/v2

v1 was published as v1.0.1 in 2021. Because v0.2.0 sorts below it, everything
released afterwards was invisible to go get, and go install .../cmd/hargo@latest
fetched 2021 code. The /v2 suffix makes the current code resolvable.

The command line interface is unaffected by the module path change. Library users
should see MIGRATING.md.

Highlights

Entry filtering on every operation. fetch, curl, run, dump, and load
all accept --url, --method, and --status, which combine. --url is a regular
expression rather than a glob, because a glob's * does not cross /, so the
intuitive *.js would match no full URL at all.

hargo dump foo.har --url '/api/' --method POST --status 200

A load test summary, with exact latency percentiles, measured throughput, and a
status breakdown:

Load test complete.
  requests    83198 in 2.998s (27747.0/sec)
  failures    0 (0.0%)
  latency     min 37µs  p50 120µs  p95 264µs  p99 420µs  max 7.9ms
  status      200=83198

Output files. hargo curl foo.har -o requests.sh and the same for dump. The
output is rendered before the file is created, so a malformed HAR leaves no
truncated file and does not clobber an existing one.

hargo run --fail-on-status, for callers that want a broken recording to exit
non-zero. Off by default, since a recorded 404 is often the expected result.

Modernised library API

  • Operations that do network I/O take a context.Context first, and cancelling it
    stops the work, including while a replay is waiting out a recorded delay.
  • Every entry point takes an io.Reader and an options struct.
  • The library is silent by default: it writes nothing and logs nothing unless given
    a Logger or a Progress writer. logrus is replaced by log/slog and is no
    longer a dependency.
  • Run/RunWithOptions and Fetch/FetchTo are merged; Validate drops its
    redundant bool; Dump and ReadStream return errors instead of logging them.
  • Har is spelled HAR throughout, matching Go's convention for initialisms.

Correctness fixes

Among many: replaying a HAR could sleep for 292 years, because startedDateTime
was parsed with a single layout that rejected the HAR spec's own example, and the
discarded error left a zero time whose difference saturates. ToCurl emitted
curl -X POST-d ..., joined cookies with & instead of the RFC 6265 "; ", and
URL-encoded them. fetch saved 4xx and 5xx bodies as though they were the
resource, sent no request body, and treated deflate as raw rather than zlib.
Recorded Host headers were silently dropped. Validate accepted trailing
garbage. Responses were closed undrained, which prevented connection reuse.

The full list is in CHANGELOG.md.

v2.0.1 vs v2.0.0

Identical for consumers; no library code differs. v2.0.1 fixes a test that assumed
a fine-grained clock and so failed on Windows, which blocked v2.0.0's release job.