Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/")
Expand Down Expand Up @@ -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`))
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/unrouted_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading