From 6945097e205470941f82fc4b6e485e8cfb61f911 Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Thu, 31 Jul 2025 17:38:10 +0200 Subject: [PATCH] Initial dump --- pkg/handler/handler.go | 3 +++ pkg/handler/unrouted_handler.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index 7953a9702..ab88842f1 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -32,6 +32,8 @@ func NewHandler(config Config) (*Handler, error) { UnroutedHandler: handler, } + // allowedMethods := []string{""} + mux := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { method := r.Method path := strings.Trim(r.URL.Path, "/") @@ -64,6 +66,7 @@ func NewHandler(config Config) (*Handler, error) { handler.DelFile(w, r) default: // TODO: Only add GET and DELETE if they are supported + // TODO: POST with X-Method-Override is allowed w.Header().Add("Allow", "GET, HEAD, PATCH, DELETE") w.WriteHeader(http.StatusMethodNotAllowed) w.Write([]byte(`method not allowed`)) diff --git a/pkg/handler/unrouted_handler.go b/pkg/handler/unrouted_handler.go index 8d2e690f7..520f88664 100644 --- a/pkg/handler/unrouted_handler.go +++ b/pkg/handler/unrouted_handler.go @@ -187,7 +187,7 @@ func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler { // Allow overriding the HTTP method. The reason for this is // that some libraries/environments do not support PATCH and // DELETE requests, e.g. Flash in a browser and parts of Java. - if newMethod := r.Header.Get("X-HTTP-Method-Override"); r.Method == "POST" && newMethod != "" { + if newMethod := r.Header.Get("X-HTTP-Method-Override"); r.Method == "POST" && (newMethod == "PATCH" || newMethod == "DELETE") { r.Method = newMethod }