38 lines
761 B
Go
38 lines
761 B
Go
//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
|
|
}
|