1
0
mirror of https://github.com/kataras/iris.git synced 2026-03-07 00:45:58 +00:00
Former-commit-id: 55589069c8ed458183d28f32870fdf8f233629c6
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-11 16:14:31 +03:00
parent 3574816e1d
commit c8ed26ee51
8 changed files with 981 additions and 923 deletions

View File

@@ -10,7 +10,7 @@ import (
"github.com/andybalholm/brotli"
"github.com/klauspost/compress/flate"
"github.com/klauspost/compress/gzip"
"github.com/klauspost/compress/s2"
"github.com/klauspost/compress/s2" // snappy output but likely faster decompression.
"github.com/klauspost/compress/snappy"
)
@@ -184,11 +184,10 @@ func AcquireCompressResponseWriter(w ResponseWriter, r *http.Request, level int)
return nil, ErrResponseNotCompressed
}
encoding := negotiateAcceptHeader(acceptEncoding, []string{"gzip", "deflate", "br", "snappy", "s2"}, "")
encoding := negotiateAcceptHeader(acceptEncoding, []string{GZIP, DEFLATE, BROTLI, SNAPPY, S2}, IDENTITY)
if encoding == "" {
return nil, fmt.Errorf("%w: %s", ErrNotSupportedCompression, encoding)
}
AddCompressHeaders(w.Header(), encoding)
v := compressWritersPool.Get().(*CompressResponseWriter)
v.ResponseWriter = w
@@ -212,6 +211,8 @@ func AcquireCompressResponseWriter(w ResponseWriter, r *http.Request, level int)
}
v.CompressWriter = encWriter
AddCompressHeaders(w.Header(), encoding)
return v, nil
}

View File

@@ -4505,6 +4505,32 @@ func (ctx *Context) Application() Application {
return ctx.app
}
const errorContextKey = "iris.context.error"
// SetErr is just a helper that sets an error value
// as a context value, it does nothing more.
// Also, by-default this error's value is written to the client
// on failures when no registered error handler is available (see `Party.On(Any)ErrorCode`).
// See `GetError` to retrieve it back.
//
// Note that, if you want to stop the chain
// with an error see the `StopWithError` instead.
func (ctx *Context) SetErr(err error) {
ctx.Values().Set(errorContextKey, err)
}
// GetErr is a helper which retrieves
// the error value stored by `SetErr`.
func (ctx *Context) GetErr() error {
if v := ctx.Values().Get(errorContextKey); v != nil {
if err, ok := v.(error); ok {
return err
}
}
return nil
}
const idContextKey = "iris.context.id"
// SetID sets an ID, any value, to the Request Context.