h2non / gock

HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽

Home Page:https://pkg.go.dev/github.com/h2non/gock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compression type matching and automatic decompression

treythomas123 opened this issue · comments

It'd be nice to have a way to specify a compression type, for testing clients that gzip their body contents. For example:

gock.New(url).
    Post("/path").
    MatchCompression("gzip").
    JSON(map[string]interface{}{
        "foo": "bar",
    }).
    Reply(200)

To accomplish this now requires a custom matcher, since the JSON matcher assumes the request body is unencoded.

I can write a PR if you're interested in including this.

Thanks!

commented

That would be great! Using just Compression() will keep it shorter but equally expressive.

commented

This feature is now shipped in gock@1.0.2. Thanks!