hotfix #186

Merged
vtolstov merged 8 commits from kgorbunov/micro-server-http:hotfix into master 2024-03-26 14:53:15 +03:00
Showing only changes of commit 68738013cc - Show all commits

View File

@ -42,10 +42,10 @@ type Handler struct {
type Option func(*Options) type Option func(*Options)
type Options struct { type Options struct {
Meter meter.Meter Meter meter.Meter
Name string Name string
MeterOptions []options.Option MeterOptions []options.Option
Gzip bool DisableCompress bool
} }
func Meter(m meter.Meter) Option { func Meter(m meter.Meter) Option {
@ -60,9 +60,9 @@ func Name(name string) Option {
} }
} }
func Gzip(g bool) Option { func DisableCompress(g bool) Option {
return func(o *Options) { return func(o *Options) {
o.Gzip = g o.DisableCompress = g
} }
} }
@ -73,7 +73,7 @@ func MeterOptions(opts ...options.Option) Option {
} }
func NewOptions(opts ...Option) Options { func NewOptions(opts ...Option) Options {
options := Options{Meter: meter.DefaultMeter, Gzip: true} options := Options{Meter: meter.DefaultMeter, DisableCompress: false}
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
} }
@ -97,7 +97,7 @@ func (h *Handler) Metrics(ctx context.Context, req *codecpb.Frame, rsp *codecpb.
w := io.Writer(buf) w := io.Writer(buf)
if md, ok := metadata.FromIncomingContext(ctx); gzipAccepted(md) && ok && h.opts.Gzip { if md, ok := metadata.FromIncomingContext(ctx); gzipAccepted(md) && ok && !h.opts.DisableCompress {
omd, _ := metadata.FromOutgoingContext(ctx) omd, _ := metadata.FromOutgoingContext(ctx)
omd.Set(contentEncodingHeader, "gzip") omd.Set(contentEncodingHeader, "gzip")
gz := gzipPool.Get().(*gzip.Writer) gz := gzipPool.Get().(*gzip.Writer)