Skip to content

Commit cf6ae82

Browse files
authored
fix: remove unnecessary gzip decompression (#182)
1 parent a6bedf2 commit cf6ae82

File tree

5 files changed

+15
-34
lines changed

5 files changed

+15
-34
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout
18-
uses: actions/checkout@v4
19-
- uses: actions/setup-go@v5
18+
uses: actions/checkout@v5
19+
- uses: actions/setup-go@v6
2020
with:
21-
go-version: "1.20"
21+
go-version: "1.22"
2222
- name: Install dependencies
2323
run: |
2424
go get -t -v ./...

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v4
16-
- uses: actions/setup-go@v5
15+
uses: actions/checkout@v5
16+
- uses: actions/setup-go@v6
1717
with:
18-
go-version: "1.20"
18+
go-version: "1.22"
1919
- name: Install dependencies
2020
run: |
2121
go get -t -v ./...

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ linters:
1414
- mnd
1515
- recvcheck
1616
- wsl
17+
- wsl_v5
18+
- godoclint
1719
- makezero
1820
- godox
1921
- gocognit
@@ -22,6 +24,7 @@ linters:
2224
- forcetypeassert
2325
- containedctx
2426
- maintidx
27+
- noinlineerr
2528
settings:
2629
exhaustive:
2730
# Program elements to check for exhaustiveness.

graphql.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package graphql
22

33
import (
44
"bytes"
5-
"compress/gzip"
65
"context"
76
"encoding/json"
87
"errors"
@@ -214,7 +213,6 @@ func (c *Client) doHttpRequest(ctx context.Context, body io.ReadSeeker) *rawGrap
214213
}
215214

216215
request.Header.Add("Content-Type", "application/json")
217-
request.Header.Add("Accept-Encoding", "gzip")
218216

219217
if c.requestModifier != nil {
220218
c.requestModifier(request)
@@ -338,28 +336,6 @@ func (c *Client) decodeRawGraphQLResponse(
338336
) *rawGraphQLResult {
339337
var r io.Reader = resp.Body
340338

341-
if resp.Header.Get("Content-Encoding") == "gzip" {
342-
gr, err := gzip.NewReader(r)
343-
if err != nil {
344-
return &rawGraphQLResult{
345-
request: req,
346-
requestBody: reqBody,
347-
Errors: Errors{
348-
newError(
349-
ErrJsonDecode,
350-
fmt.Errorf("problem trying to create gzip reader: %w", err),
351-
),
352-
},
353-
}
354-
}
355-
356-
defer func() {
357-
_ = gr.Close()
358-
}()
359-
360-
r = gr
361-
}
362-
363339
// copy the response reader for debugging
364340
var respReader *bytes.Reader
365341

@@ -760,7 +736,9 @@ const (
760736
queryOperation operationType = iota
761737
mutationOperation
762738
// subscriptionOperation // Unused.
739+
)
763740

741+
const (
764742
ErrRequestError = "request_error"
765743
ErrJsonEncode = "json_encode_error"
766744
ErrJsonDecode = "json_decode_error"

graphql_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,10 @@ func TestClient_Query_Compression(t *testing.T) {
985985
gw.Close()
986986
})
987987

988-
client := graphql.NewClient(
989-
"/graphql",
990-
&http.Client{Transport: localRoundTripper{handler: mux}},
991-
)
988+
server := httptest.NewServer(mux)
989+
defer server.Close()
990+
991+
client := graphql.NewClient(server.URL+"/graphql", http.DefaultClient)
992992

993993
var q struct {
994994
User struct {

0 commit comments

Comments
 (0)