Created
February 1, 2022 15:15
-
-
Save wperron/11ab95a64e2c377a446f3c61e0590314 to your computer and use it in GitHub Desktop.
Manually setting Accept-Encoding on a request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"log" | |
"net/http" | |
"net/url" | |
"github.com/klauspost/compress/gzhttp" | |
) | |
func main() { | |
http.DefaultClient.Transport = gzhttp.Transport(http.DefaultTransport) | |
url, err := url.Parse("https://example.org") | |
if err != nil { | |
log.Fatal(err) | |
} | |
req := &http.Request{ | |
Method: "GET", | |
URL: url, | |
Header: http.Header{ | |
"Accept-Encoding": {"gzip"}, | |
}, | |
} | |
resp, err := http.DefaultClient.Do(req) | |
if err != nil { | |
log.Fatal(err) | |
return | |
} | |
fmt.Println(io.ReadAll(resp.Body)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment