leviysoft / mockingbird

Flexible mock server
Apache License 2.0
9 stars 3 forks source link

fix: HTTP stub can't return 204 (no content) code #32

Closed ashashev closed 8 months ago

ashashev commented 9 months ago

Returning 204/304 codes fails

For tapir, an endpoint that returns code 204 (No Content) must not have any out, regardless of whether the returning data is empty or not. This fix adds a handler for when th stub retusn code 204.

Steps for reproducing

  1. Create a service
curl -X POST $host/api/internal/mockingbird/v2/service \
  -d '{"name": "alpha", "suffix": "alpha"}'
  1. Create a stub
curl -i -X POST $host/api/internal/mockingbird/v2/stub \
  -d '
{
  "path": "/alpha/noc",
  "pathPattern": null,
  "name": "HTTP ***",
  "labels": [],
  "method": "GET",
  "scope": "persistent",
  "request": {
    "mode": "no_body",
    "query": null,
    "headers": {}
  },
  "response": {
    "mode": "raw",
    "body": "",
    "code": 204,
    "headers": {}
  },
  "state": null,
  "seed": null,
  "service": "alpha"
}
'
  1. Call the stub
curl -i http://localhost:8228/api/mockingbird/exec/alpha/noc

The expected behavior is the call returns code 204, but in reality it returns code 500 (Internal Server Error).

Returning arbitrary codes fails, for example 418

  1. Create a stub
curl -i -X POST $host/api/internal/mockingbird/v2/stub \
  -d '
{
  "path": "/alpha/418",
  "pathPattern": null,
  "name": "HTTP ***",
  "labels": [],
  "method": "GET",
  "scope": "persistent",
  "request": {
    "mode": "no_body",
    "query": null,
    "headers": {}
  },
  "response": {
    "mode": "raw",
    "body": "OK",
    "code": 418,
    "headers": {}
  },
  "state": null,
  "seed": null,
  "service": "alpha"
}
'
  1. Call the stub
curl -i http://localhost:8228/api/mockingbird/exec/alpha/418

The expected behavior is the call returns code 418 with body OK, but in reality it returns nothing, the call fails with timeout, because Mockingbird can handle only specified codes.

@mockingbird/maintainers