Skip to content

API, UX: return 4xx on invalid input for delete method #5836

@tetra12

Description

@tetra12

Caddy : v2.7.4 + (master)
OS: Ubuntu 22.04
Module: API

Issue:
When I delete a non-existing listener, Caddy returns 200 instead of 4xx.

Reproduce:

  1. caddy run (no config)
  2. Add a route:

hello.json

{
  "apps": {
    "http": {
      "servers": {
        "example": {
          "listen": [":2015"],
          "routes": [
            {
              "handle": [
                {
                  "handler": "static_response",
                  "body": "Hello, world!"
                }
              ]
            }
          ]
        }
      }
    }
  }
}

curl localhost:2019/load -H "Content-Type: application/json" -d @hello.json

  1. Validate the route:
    curl localhost:2019/config/
{"apps":{"http":{"servers":{"example":{"listen":[":2015"],"routes":[{"handle":[{"body":"Hello, world!","handler":"static_response"}]}]}}}}}
  1. Delete the route, providing an invalid parameter - foo:
    curl -I -X DELETE "http://localhost:2019/config/apps/http/servers/foo"
HTTP/1.1 **200 OK** <---------------------- This is BAD
Date: Sat, 23 Sep 2023 16:03:58 GMT
Content-Length: 0
  1. Check deleted route again:
    curl localhost:2019/config/
{"apps":{"http":{"servers":{"example":{"listen":[":2015"],"routes":[{"handle":[{"body":"Hello, world!","handler":"static_response"}]}]}}}}}

Actual Result:
As we see from Step 4, Caddy returns 200 on delete. However, my input was invalid and the route was NOT deleted.
This behavior results in issues for API integrators, because you never know whether the requested route was actually deleted or a misinput occured

Expected Result:
Caddy returns 4xx on invalid request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions