Skip to content

Commit bc56c6e

Browse files
authored
client: request zstd compression from the server (#37)
Since the server allows requesting zstd compression of the response, include that in the client as well.
1 parent 7577b16 commit bc56c6e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

client/tailsql/client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"net/url"
1313
"strings"
1414

15+
"github.com/klauspost/compress/zstd"
1516
server "github.com/tailscale/tailsql/server/tailsql"
1617
)
1718

@@ -120,6 +121,7 @@ func callGET(ctx context.Context, do func(*http.Request) (*http.Response, error)
120121
if err != nil {
121122
return nil, fmt.Errorf("new request: %w", err)
122123
}
124+
req.Header.Set("Accept-Encoding", "zstd")
123125
req.Header.Set("Sec-Tailsql", "ok")
124126
rsp, err := do(req)
125127
if err != nil {
@@ -136,5 +138,13 @@ func callGET(ctx context.Context, do func(*http.Request) (*http.Response, error)
136138
}
137139
return nil, errors.New(msg)
138140
}
141+
if rsp.Header.Get("Content-Encoding") == "zstd" {
142+
dec, err := zstd.NewReader(rsp.Body)
143+
if err != nil {
144+
rsp.Body.Close()
145+
return nil, fmt.Errorf("new zstd decoder: %w", err)
146+
}
147+
return dec.IOReadCloser(), nil
148+
}
139149
return rsp.Body, nil
140150
}

0 commit comments

Comments
 (0)