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

[BUGFIX]: set Content-Type for non GET requests only #6341

Merged
merged 5 commits into from
Aug 23, 2019

Conversation

snewcomer
Copy link
Contributor

@snewcomer snewcomer commented Aug 17, 2019

  • ensure fetch nor ajax sets content-type header if GET request
  • if existing Content-Type header, don't add another one
  • add tests

Piggybacked off of #6169 with some tests and default content type header

close #6341 #6167 #6324

@@ -143,6 +143,8 @@ import { pluralize } from 'ember-inflector';
const JSONAPIAdapter = RESTAdapter.extend({
defaultSerializer: '-json-api',

defaultContentType: 'application/vnd.api+json',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

perhaps privatize with _?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes please

options = fetchOptions(options, this);
} else {
if (options.data && options.type !== 'GET') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A GET request with a non-simple content-type will result in a preflight request. One consequence of adding the Content-Type header on GET (where we used to not) is the backend server perhaps doesn't expect this and won't return the right a-c-a-o header.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we leave this explanation of this conditional as a comment in the code?

Copy link
Contributor

@runspired runspired left a comment

Choose a reason for hiding this comment

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

Overall is good but needs a tiny bit of cleanup prior to merge

@brandynbennett
Copy link

brandynbennett commented Oct 8, 2019

@snewcomer Is this fix part of any release?

@runspired
Copy link
Contributor

@brandynbennett it is in beta

@brandynbennett
Copy link

brandynbennett commented Oct 9, 2019 via email

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

3 participants