Skip to content

Commit

Permalink
refactor(issue-34): simplify by using httpvalidator for min proto
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaba505 committed Dec 18, 2023
1 parent 435b1d8 commit 8197df0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,17 @@ func (rt *Runtime) Run(ctx context.Context) error {
ls = tls.NewListener(ls, rt.tlsConfig)
}

handler := rt.h
if rt.http2Only {
handler = httpvalidate.Request(
rt.h,
httpvalidate.MinProto(2, 0),
)
}

s := &http.Server{
Handler: otelhttp.NewHandler(
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)
}),
handler,
"server",
otelhttp.WithMessageEvents(otelhttp.ReadEvents, otelhttp.WriteEvents),
),
Expand Down

0 comments on commit 8197df0

Please sign in to comment.