-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Content-type handling in DELETE and PUT methods #77
Content-type handling in DELETE and PUT methods #77
Conversation
body?: any, | ||
) => { | ||
// For PUT and DELETE methods, do not set Content-Type if no body is provided. | ||
if (['PUT', 'DELETE'].includes(method) && !body) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small performance improvement: we could check !body before calling the includes(). Might be faster for all requests that have body specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s a good point!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (['PUT', 'DELETE'].includes(method) && !body) { | |
if (!body && ['PUT', 'DELETE'].includes(method)) { |
I mean I was suggesting this one, not sure if you forgot 😄 I think we can merge and release after this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saewoohan I think it was all good, I was about to merge it in fact 😄 Can you reopen please?
|
||
// Automatically set Content-Type to 'application/json;charset=utf-8' if not already present. | ||
if (headers instanceof Headers) { | ||
if (!headers.has(CONTENT_TYPE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit-pick] I'd suggest merging this nested if condition into the upper one and just use return;
. This way we merge ifs, and remove else
so it should save some bytes 😄
Features:
Added Content-Type handling for DELETE and PUT methods.
First, checked if a body is provided. If no body is provided,
Then checked if Content-Type is explicitly set in requestConfig. If not explicitly set, remove the Content-Type header.
Additionally, I added some unit tests 😎
#75