refactor(http): drop custom transport and let the client set Accept-Encoding (#847)
This commit is contained in:
parent
f2e837a758
commit
2d698f0c7e
6 changed files with 7 additions and 44 deletions
6
go.mod
6
go.mod
|
|
@ -4,6 +4,8 @@ go 1.27.0
|
|||
|
||||
// replace github.com/ayn2op/tview => ../tview
|
||||
|
||||
replace github.com/bogdanfinn/fhttp => github.com/ayn2op/fhttp v0.6.10-0.20261016015330-2d5e34c6b935
|
||||
|
||||
// replace (
|
||||
// github.com/ayn2op/arikawa/v3 => ../arikawa
|
||||
// github.com/ayn2op/ningen/v3 => ../ningen
|
||||
|
|
@ -12,7 +14,6 @@ go 1.27.0
|
|||
require (
|
||||
github.com/BurntSushi/toml v1.6.0
|
||||
github.com/alecthomas/chroma/v2 v2.27.0
|
||||
github.com/andybalholm/brotli v1.2.6
|
||||
github.com/ayn2op/arikawa/v3 v3.0.0-20261014035141-32b58d8f3755
|
||||
github.com/ayn2op/ningen/v3 v3.0.1-0.20261014035153-5e43590a1426
|
||||
github.com/ayn2op/tview v0.0.0-20261015233535-ab884c65f4fe
|
||||
|
|
@ -21,7 +22,6 @@ require (
|
|||
github.com/gdamore/tcell/v3 v3.6.0
|
||||
github.com/gen2brain/malgo v0.11.26
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/klauspost/compress v1.20.3
|
||||
github.com/mattn/go-shellwords v1.0.16
|
||||
github.com/ncruces/zenity v0.10.15
|
||||
github.com/rivo/uniseg v0.4.7
|
||||
|
|
@ -38,6 +38,7 @@ require (
|
|||
|
||||
require (
|
||||
github.com/akavel/rsrc v0.10.2 // indirect
|
||||
github.com/andybalholm/brotli v1.2.6 // indirect
|
||||
github.com/bdandy/go-errors v1.2.2 // indirect
|
||||
github.com/bdandy/go-socks4 v1.2.3 // indirect
|
||||
github.com/bogdanfinn/quic-go-utls v1.0.10-utls // indirect
|
||||
|
|
@ -55,6 +56,7 @@ require (
|
|||
github.com/godbus/dbus/v5 v5.2.4 // indirect
|
||||
github.com/gorilla/schema v1.4.1 // indirect
|
||||
github.com/josephspurrier/goversioninfo v1.7.0 // indirect
|
||||
github.com/klauspost/compress v1.20.3 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.4.1 // indirect
|
||||
github.com/quic-go/qpack v0.6.0 // indirect
|
||||
github.com/randall77/makefat v0.0.0-20260406194835-1b91746796b7 // indirect
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -12,6 +12,8 @@ github.com/andybalholm/brotli v1.2.6 h1:ftYnfj6usCp+UGV5kSJ3+chpMQgU+gJf/AxsUQ52
|
|||
github.com/andybalholm/brotli v1.2.6/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
|
||||
github.com/ayn2op/arikawa/v3 v3.0.0-20261014035141-32b58d8f3755 h1:XHo9kizImaAEtJJky4GZOBTalze42GIVDViqirjuPBY=
|
||||
github.com/ayn2op/arikawa/v3 v3.0.0-20261014035141-32b58d8f3755/go.mod h1:YARcqZmk7hDjXB+lexlXX4wDFHULafbGnF0gsD0tuNw=
|
||||
github.com/ayn2op/fhttp v0.6.10-0.20261016015330-2d5e34c6b935 h1:oVxkY1/nVsVQ8Cn/hxJckflbBEUkd5PBLOELAeAhGLA=
|
||||
github.com/ayn2op/fhttp v0.6.10-0.20261016015330-2d5e34c6b935/go.mod h1:7phoj3f/q54WuiTnCTlAhEoaVcdlruKkSzCSD47LzHk=
|
||||
github.com/ayn2op/ningen/v3 v3.0.1-0.20261014035153-5e43590a1426 h1:0ndRWpAiSSgR0z9b7K+pwMlCHEk3VzQeS5ls+zWtbr0=
|
||||
github.com/ayn2op/ningen/v3 v3.0.1-0.20261014035153-5e43590a1426/go.mod h1:4S2B9frwrjELeAldoqPgasA/VfnOySgRlektwYLuVks=
|
||||
github.com/ayn2op/tview v0.0.0-20261015233535-ab884c65f4fe h1:XBuBkzSmoomT6agxYt2d5+1WNF4T+AFuI52lZsrD8/I=
|
||||
|
|
@ -20,8 +22,6 @@ github.com/bdandy/go-errors v1.2.2 h1:WdFv/oukjTJCLa79UfkGmwX7ZxONAihKu4V0mLIs11
|
|||
github.com/bdandy/go-errors v1.2.2/go.mod h1:NkYHl4Fey9oRRdbB1CoC6e84tuqQHiqrOcZpqFEkBxM=
|
||||
github.com/bdandy/go-socks4 v1.2.3 h1:Q6Y2heY1GRjCtHbmlKfnwrKVU/k81LS8mRGLRlmDlic=
|
||||
github.com/bdandy/go-socks4 v1.2.3/go.mod h1:98kiVFgpdogR8aIGLWLvjDVZ8XcKPsSI/ypGrO+bqHI=
|
||||
github.com/bogdanfinn/fhttp v0.6.9 h1:F9MsWR1K6JMRlXN4Q/MfjYmptr29nCdycQo+OPBG5U0=
|
||||
github.com/bogdanfinn/fhttp v0.6.9/go.mod h1:7phoj3f/q54WuiTnCTlAhEoaVcdlruKkSzCSD47LzHk=
|
||||
github.com/bogdanfinn/quic-go-utls v1.0.10-utls h1:oZN+J3OKMmWaVbI/sx4ULvHiAXbWJKVcvEFW4fkybMU=
|
||||
github.com/bogdanfinn/quic-go-utls v1.0.10-utls/go.mod h1:bBLJ2Vy68Q7y6VfbG9czd825rTcQua7n+y12RM9Q588=
|
||||
github.com/bogdanfinn/tls-client v1.16.0 h1:km3YLI6CMRLZnfrC+hGStePPryIicd3hoxFQvHB1itY=
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func NewClient(token string) *api.Client {
|
||||
stdClient := http.Client{Transport: newTransport()}
|
||||
stdClient := http.Client{}
|
||||
httpClient := httputil.NewClientWithDriver(httpdriver.WrapClient(stdClient))
|
||||
client := api.NewCustomClient(token, httpClient)
|
||||
client.UserAgent = BrowserUserAgent()
|
||||
|
|
@ -13,7 +13,6 @@ func Headers() stdHttp.Header {
|
|||
headers := make(stdHttp.Header)
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers
|
||||
headers.Set("Accept", "*/*")
|
||||
headers.Set("Accept-Encoding", "gzip, deflate, br, zstd")
|
||||
headers.Set("Accept-Language", "en-US,en;q=0.9")
|
||||
headers.Set("Origin", api.BaseEndpoint)
|
||||
headers.Set("Priority", "u=1, i")
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
//go:build no_spoof_tls_fingerprint
|
||||
|
||||
package http
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/andybalholm/brotli"
|
||||
"github.com/klauspost/compress/gzhttp"
|
||||
)
|
||||
|
||||
type transport struct {
|
||||
base http.RoundTripper
|
||||
}
|
||||
|
||||
func newTransport() *transport {
|
||||
return &transport{
|
||||
base: gzhttp.Transport(http.DefaultTransport, gzhttp.TransportAlwaysDecompress(true)),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
resp, err := t.base.RoundTrip(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Header.Get("Content-Encoding") == "br" {
|
||||
resp.Body = io.NopCloser(brotli.NewReader(resp.Body))
|
||||
resp.Header.Del("Content-Encoding")
|
||||
resp.Header.Del("Content-Length")
|
||||
resp.ContentLength = -1
|
||||
resp.Uncompressed = true
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue