mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 10:57:05 +00:00
add a new 'Context.GzipReader(bool) method and 'iris.GzipReader' middleware as requested at #1528
Former-commit-id: 7665545069bf1784d17a9db1e5f9f5f8df4b0c43
This commit is contained in:
38
_examples/http_request/read-gzip/main_test.go
Normal file
38
_examples/http_request/read-gzip/main_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris/v12/httptest"
|
||||
)
|
||||
|
||||
func TestGzipReader(t *testing.T) {
|
||||
app := newApp()
|
||||
|
||||
expected := payload{Message: "test"}
|
||||
b, err := json.Marshal(expected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
w := gzip.NewWriter(buf)
|
||||
_, err = w.Write(b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = w.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
e := httptest.New(t, app)
|
||||
// send gzip compressed.
|
||||
e.POST("/").WithHeader("Content-Encoding", "gzip").WithHeader("Content-Type", "application/json").
|
||||
WithBytes(buf.Bytes()).Expect().Status(httptest.StatusOK).Body().Equal(expected.Message)
|
||||
// raw.
|
||||
e.POST("/").WithJSON(expected).Expect().Status(httptest.StatusOK).Body().Equal(expected.Message)
|
||||
}
|
||||
Reference in New Issue
Block a user