mirror of
https://github.com/kataras/iris.git
synced 2026-03-07 00:45:58 +00:00
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user