change set md
This commit is contained in:
		| @@ -41,9 +41,10 @@ type Handler struct { | ||||
| type Option func(*Options) | ||||
|  | ||||
| type Options struct { | ||||
| 	Meter        meter.Meter | ||||
| 	Name         string | ||||
| 	MeterOptions []meter.Option | ||||
| 	Meter           meter.Meter | ||||
| 	Name            string | ||||
| 	MeterOptions    []meter.Option | ||||
| 	DisableCompress bool | ||||
| } | ||||
|  | ||||
| func Meter(m meter.Meter) Option { | ||||
| @@ -58,6 +59,12 @@ func Name(name string) Option { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func DisableCompress(g bool) Option { | ||||
| 	return func(o *Options) { | ||||
| 		o.DisableCompress = g | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func MeterOptions(opts ...meter.Option) Option { | ||||
| 	return func(o *Options) { | ||||
| 		o.MeterOptions = append(o.MeterOptions, opts...) | ||||
| @@ -65,7 +72,7 @@ func MeterOptions(opts ...meter.Option) Option { | ||||
| } | ||||
|  | ||||
| func NewOptions(opts ...Option) Options { | ||||
| 	options := Options{Meter: meter.DefaultMeter} | ||||
| 	options := Options{Meter: meter.DefaultMeter, DisableCompress: false} | ||||
| 	for _, o := range opts { | ||||
| 		o(&options) | ||||
| 	} | ||||
| @@ -89,8 +96,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.FromOutgoingContext(ctx); gzipAccepted(md) && ok && !h.opts.DisableCompress { | ||||
| 		omd, _ := metadata.FromOutgoingContext(ctx) | ||||
| 		omd.Set(contentEncodingHeader, "gzip") | ||||
| 		gz := gzipPool.Get().(*gzip.Writer) | ||||
| 		defer gzipPool.Put(gz) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user