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

Content-type handling in DELETE and PUT methods #77

Closed
wants to merge 9 commits into from
Closed

Content-type handling in DELETE and PUT methods #77

wants to merge 9 commits into from

Conversation

saewoohan
Copy link

@saewoohan saewoohan commented Oct 12, 2024

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

body?: any,
) => {
// For PUT and DELETE methods, do not set Content-Type if no body is provided.
if (['PUT', 'DELETE'].includes(method) && !body) {
Copy link
Owner

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.

Copy link
Author

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!

Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Owner

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)) {
Copy link
Owner

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 😄

@saewoohan saewoohan closed this by deleting the head repository Oct 23, 2024
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.

2 participants