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

Set "Content-Length" header for response(...).emtpy() #56

Closed
christoph-fricke opened this issue Jun 18, 2024 · 0 comments · Fixed by #58
Closed

Set "Content-Length" header for response(...).emtpy() #56

christoph-fricke opened this issue Jun 18, 2024 · 0 comments · Fixed by #58
Labels
feature Improvements or additions to the public API

Comments

@christoph-fricke
Copy link
Owner

openapi-fetch skips parsing the response body when the status code is 204 or the content-length header is 0 (Source Code). For other status codes (like 201), request handlers have to explicitly set the content-length header when creating empty responses to avoid JSON parsing errors in openapi-fetch.

response(201).empty({ headers: { 'Content-Length': '0' } })

When using HttpResponse.json() or HttpResponse.text() MSW calculates the content-length. Otherwise, the header is not calculated implicitly for every response.
For a better developer experience we should set the content-length header implicitly as well, when empty responses are created. This avoids confusing problems when using response(201).empty().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Improvements or additions to the public API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant