From d8f356f560384d495d6df3fa395a81abcd502e40 Mon Sep 17 00:00:00 2001 From: Zaba505 Date: Sun, 17 Dec 2023 20:30:29 -0500 Subject: [PATCH] fix(issue-34): support only allow http2 requests if config is set --- http/http.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/http/http.go b/http/http.go index b389adc..0166af4 100644 --- a/http/http.go +++ b/http/http.go @@ -180,7 +180,13 @@ func (rt *Runtime) Run(ctx context.Context) error { s := &http.Server{ Handler: otelhttp.NewHandler( - rt.h, + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if rt.http2Only && r.ProtoMajor < 2 { + w.WriteHeader(http.StatusUnauthorized) + return + } + rt.h.ServeHTTP(w, r) + }), "server", otelhttp.WithMessageEvents(otelhttp.ReadEvents, otelhttp.WriteEvents), ),