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

Setting the Content-Type header in POST requests do not overwrite default header #1919

Closed
tskillian opened this Issue Jul 28, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@tskillian
Copy link

tskillian commented Jul 28, 2017

If you make a POST request and set the Content-Type header, it will not overwrite the default Content-Type header but rather will get appended to the default header. This does not happen in GET requests. I have not attempted this with any other types.

Expected Behavior

The expectation is that setting a header in POST requests actually means setting the header, rather than appending to some default header.

Current Behavior

The Content-Type header set by the user will get appended to the default header

Steps to Reproduce (for bugs)

Look at the network tab for the below fiddle after running, you'll see the POST request made by the code and see that the Content-Type header is not what the user set it to.
Repro: https://jsfiddle.net/2bmk0zjs/2/

@tskillian

This comment has been minimized.

Copy link

tskillian commented Jul 28, 2017

Found the culprit.. mithril assumes that setRequestHeader would overwrite (like any sort of setter/getter...). For some crazy reason this is not the actual beheavior of the method:

The XMLHttpRequest.setRequestHeader() method sets the value of an HTTP request header. You must call setRequestHeader()after open(), but before send(). If this method is called several times with the same header, the values are merged into one single request header.

Source: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader

@pygy pygy added the bug label Jul 28, 2017

@pygy

This comment has been minimized.

Copy link
Member

pygy commented Jul 28, 2017

Thanks for the report @tskillian, here's the culprit.

@pygy pygy closed this in #1924 Aug 3, 2017

pygy added a commit that referenced this issue Aug 3, 2017

Merge pull request #1924 from tskillian/fixRequestContentHeaders
Fix Content-Type header bug (Issue #1919)

@pygy pygy referenced this issue Oct 13, 2017

Merged

re fix issue #1919 for the v1 branch #1989

0 of 4 tasks complete

pygy added a commit that referenced this issue Oct 13, 2017

Merge pull request #1989 from pygy/re-fix-1919-for-v1
re fix issue #1919 for the v1 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment