Swap buggy timeout code for http.TimeoutHandler

This commit is contained in:
Jonny Stoten
2024-06-11 11:19:52 +01:00
parent f9195a2133
commit 11a0d75e80
3 changed files with 31 additions and 30 deletions

View File

@@ -7,6 +7,7 @@ import (
"io"
"net/http"
"path/filepath"
"runtime/debug"
"github.com/docker/attest/pkg/attest"
"github.com/docker/attest/pkg/oci"
@@ -18,7 +19,17 @@ import (
"k8s.io/klog/v2"
)
func Handler(w http.ResponseWriter, req *http.Request) {
func Handler() http.Handler {
return http.HandlerFunc(handler)
}
func handler(w http.ResponseWriter, req *http.Request) {
defer func() {
if r := recover(); r != nil {
klog.Error(string(debug.Stack()))
klog.ErrorS(fmt.Errorf("%v", r), "panic occurred")
}
}()
// read request body
requestBody, err := io.ReadAll(req.Body)