Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Dec 14, 2023

Conversation

ashashev
Copy link
Contributor

@ashashev ashashev commented Dec 6, 2023

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

@ashashev ashashev marked this pull request as draft December 6, 2023 20:00
@ashashev ashashev force-pushed the fix/http-stub-cant-return-204 branch 3 times, most recently from c0be60a to baf6fe7 Compare December 11, 2023 22:04
@ashashev ashashev marked this pull request as ready for review December 11, 2023 22:04
For tapir, an endpoint that returns codes 204 or 304 must not have
any out, regardless of whether the returning data is empty or not. This
fix adds a handler for when the stub return code 204 or 304.

Also, HTTP stub can return arbitrary HTTP code, for example 418.
@ashashev ashashev force-pushed the fix/http-stub-cant-return-204 branch from baf6fe7 to f2aa191 Compare December 13, 2023 18:35
Copy link
Member

@danslapman danslapman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@danslapman danslapman merged commit 121142b into leviysoft:main Dec 14, 2023
7 checks passed
@ashashev ashashev deleted the fix/http-stub-cant-return-204 branch December 14, 2023 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants