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 83fc7c54ca - Show all commits

View File

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