diff --git a/README.md b/README.md index 90eda8f..1546141 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Features include: - CBOR ([RFC 7049](https://tools.ietf.org/html/rfc7049), ) - MessagePack () - Amazon Ion () - - Gzip ([RFC 1952](https://tools.ietf.org/html/rfc1952)) and Brotli ([RFC 7932](https://tools.ietf.org/html/rfc7932)) content encoding + - Gzip ([RFC 1952](https://tools.ietf.org/html/rfc1952)), Deflate ([RFC 1951](https://datatracker.ietf.org/doc/html/rfc1951)), and Brotli ([RFC 7932](https://tools.ietf.org/html/rfc7932)) content encoding - Standardized [hypermedia](https://smartbear.com/learn/api-design/what-is-hypermedia/) parsing into queryable/followable response links: - HTTP Link relation headers ([RFC 5988](https://tools.ietf.org/html/rfc5988#section-6.2.2)) - [HAL](http://stateless.co/hal_specification.html) diff --git a/cli/cli.go b/cli/cli.go index e84e6f7..e3defe3 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -689,6 +689,7 @@ func initCache(appName string) { // the CLI. func Defaults() { // Register content encodings + AddEncoding("deflate", &DeflateEncoding{}) AddEncoding("gzip", &GzipEncoding{}) AddEncoding("br", &BrotliEncoding{}) diff --git a/cli/encoding.go b/cli/encoding.go index 14f7f7a..ffd82c7 100644 --- a/cli/encoding.go +++ b/cli/encoding.go @@ -1,6 +1,7 @@ package cli import ( + "compress/flate" "compress/gzip" "fmt" "io" @@ -62,6 +63,14 @@ func DecodeResponse(resp *http.Response) error { return nil } +// DeflateEncoding supports gzip-encoded response content. +type DeflateEncoding struct{} + +// Reader returns a new reader for the stream that removes the gzip encoding. +func (g DeflateEncoding) Reader(stream io.Reader) (io.Reader, error) { + return flate.NewReader(stream), nil +} + // GzipEncoding supports gzip-encoded response content. type GzipEncoding struct{} diff --git a/cli/encoding_test.go b/cli/encoding_test.go index 55e1f53..70babbc 100644 --- a/cli/encoding_test.go +++ b/cli/encoding_test.go @@ -2,6 +2,7 @@ package cli import ( "bytes" + "compress/flate" "compress/gzip" "io" "net/http" @@ -19,6 +20,14 @@ func gzipEnc(data string) []byte { return b.Bytes() } +func deflateEnc(data string) []byte { + b := bytes.NewBuffer(nil) + w, _ := flate.NewWriter(b, 1) + w.Write([]byte(data)) + w.Close() + return b.Bytes() +} + func brEnc(data string) []byte { b := bytes.NewBuffer(nil) w := brotli.NewWriter(b) @@ -34,6 +43,7 @@ var encodingTests = []struct { }{ {"none", "", []byte("hello world")}, {"gzip", "gzip", gzipEnc("hello world")}, + {"deflate", "deflate", deflateEnc("hello world")}, {"brotli", "br", brEnc("hello world")}, } diff --git a/docs/README.md b/docs/README.md index f70a31c..c459a82 100644 --- a/docs/README.md +++ b/docs/README.md @@ -40,7 +40,7 @@ Start with the [guide](/guide.md) to learn how to install and configure Restish - CBOR ([RFC 7049](https://tools.ietf.org/html/rfc7049), ) - MessagePack () - Amazon Ion () - - Gzip ([RFC 1952](https://tools.ietf.org/html/rfc1952)) and Brotli ([RFC 7932](https://tools.ietf.org/html/rfc7932)) content encoding + - Gzip ([RFC 1952](https://tools.ietf.org/html/rfc1952)), Deflate ([RFC 1951](https://datatracker.ietf.org/doc/html/rfc1951)), and Brotli ([RFC 7932](https://tools.ietf.org/html/rfc7932)) content encoding - Standardized [hypermedia](https://smartbear.com/learn/api-design/what-is-hypermedia/) parsing into queryable/followable response links: - HTTP Link relation headers ([RFC 5988](https://tools.ietf.org/html/rfc5988#section-6.2.2)) - [HAL](http://stateless.co/hal_specification.html)