1
0
Fork 0

Keep status when stream mode and compress

This commit is contained in:
SALLEYRON Julien 2017-11-09 00:48:03 +01:00 committed by Traefiker
parent 58a438167b
commit 9bd0fff319
6 changed files with 40 additions and 6 deletions

View file

@ -137,6 +137,31 @@ func TestIntegrationShouldNotCompress(t *testing.T) {
}
}
func TestShouldWriteHeaderWhenFlush(t *testing.T) {
comp := &Compress{}
negro := negroni.New(comp)
negro.UseHandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
rw.Header().Add(contentEncodingHeader, gzipValue)
rw.Header().Add(varyHeader, acceptEncodingHeader)
rw.WriteHeader(http.StatusUnauthorized)
rw.(http.Flusher).Flush()
rw.Write([]byte("short"))
})
ts := httptest.NewServer(negro)
defer ts.Close()
req := testhelpers.MustNewRequest(http.MethodGet, ts.URL, nil)
req.Header.Add(acceptEncodingHeader, gzipValue)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusUnauthorized, resp.StatusCode)
assert.Equal(t, gzipValue, resp.Header.Get(contentEncodingHeader))
assert.Equal(t, acceptEncodingHeader, resp.Header.Get(varyHeader))
}
func TestIntegrationShouldCompress(t *testing.T) {
fakeBody := generateBytes(100000)

View file

@ -3,8 +3,9 @@ package middlewares
//Middleware based on https://github.com/unrolled/secure
import (
"github.com/containous/traefik/types"
"net/http"
"github.com/containous/traefik/types"
)
// HeaderOptions is a struct for specifying configuration options for the headers middleware.

View file

@ -3,11 +3,12 @@ package middlewares
//Middleware tests based on https://github.com/unrolled/secure
import (
"github.com/containous/traefik/testhelpers"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
"github.com/containous/traefik/testhelpers"
"github.com/stretchr/testify/assert"
)
var myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {