No compression for small contents
package handler
import (
+ "bytes"
"context"
+ "io"
+ "io/ioutil"
"net"
"net/http"
"runtime/debug"
@@ -16,6 +19,7 @@ import (
"github.com/avenga/couper/errors"
"github.com/avenga/couper/eval"
"github.com/avenga/couper/handler/producer"
+ "github.com/avenga/couper/server/wrapper"
)
var _ http.Handler = &Endpoint{}
@@ -165,6 +169,27 @@ func (e *Endpoint) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
default:
}
+ if clientres.Body != nil {
+ b, err := ioutil.ReadAll(clientres.Body)
+ if err != nil {
+ log.Error(err)
+ }
+
+ if len(b) > 0 {
+ clientres.Body = io.NopCloser(bytes.NewBuffer(b)) // reset
+ }
+
+ if len(b) < 60 {
+ if w, ok := rw.(*wrapper.RWWrapper); ok {
+ w.DisableCompression()
+ }
+ }
+ } else {
+ if w, ok := rw.(*wrapper.RWWrapper); ok {
+ w.DisableCompression()
+ }
+ }
+
if err = clientres.Write(rw); err != nil {
log.Errorf("endpoint write: %v", err)
}
