Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrUnsupportedEncoding ¶
type ErrUnsupportedEncoding struct { // original http response Original *http.Response Encoding string }
ErrUnsupportedEncoding represents unsupported encoding error
func (*ErrUnsupportedEncoding) Error ¶
func (e *ErrUnsupportedEncoding) Error() string
Error implements the error interface
type RoundTripper ¶
type RoundTripper struct { // Wrap is the actual RoundTripper. If Wrap is nil, http.DefaultTransport will be used Wrap http.RoundTripper }
RoundTripper is an implementation of the http.RoundTripper, that automatically decompresses the response body according to the Content-Encoding header
Example ¶
cli := http.Client{ // decompress.RoundTripper is automatically decompresses the response body according to the Content-Encoding header Transport: &decompress.RoundTripper{}, } svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { w.Header().Set("Content-Encoding", "gzip") b := gzipBytes([]byte("foobarbaz")) w.Write(b) })) req, _ := http.NewRequest("GET", svr.URL, nil) req.Header.Set("Accept-Encoding", "gzip") resp, _ := cli.Do(req) b, _ := io.ReadAll(resp.Body) resp.Body.Close() fmt.Println(string(b))
Output: foobarbaz
func (*RoundTripper) RoundTrip ¶
RoundTrip implements the RoundTrip method of the http.RoundTripper. If the response body is compressed, decompress it according to the Content-Encoding header before returning it. Supported Content-Encoding is:
- gzip
- deflate
- br
- identity
If an unsupported value is set, ErrUnsupportedEncoding will be returned. You can retrieve the original http.Response from ErrUnsupportedEncoding.
Click to show internal directories.
Click to hide internal directories.