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

Let the browser figure out the Content-Type when possible. #80

Merged
merged 1 commit into from Jul 10, 2015

Conversation

rictic
Copy link
Contributor

@rictic rictic commented Jul 9, 2015

Here's the current algorithm. The first rule that matches is what's used:

  • If the user has specified a Content-Type in this.headers, use that.
  • If the user has specified a Content-Type in this.contentType, use that.
  • If the body of the request is a string, set a Content-Type of
    application/x-www-form-urlencoded
  • Leave the Content-Type blank so that the browser can handle it.

This way we get correct handling of FormData, XML, etc for free.

Addresses #79 #78 #77 #67 and to some degree #51 and #41

Here's the current algorithm. The first rule that matches is what's used:

  * If the user has specified a Content-Type in this.headers, use that.
  * If the user has specified a Content-Type in this.contentType, use that.
  * If the body of the request is a string, set a Content-Type of
    application/x-www-form-urlencoded
  * Leave the Content-Type blank so that the browser can handle it.
@@ -118,7 +118,7 @@
*/
contentType: {
type: String,
value: 'application/x-www-form-urlencoded'
value: null
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a (potentially undesired) side-effect of making this null by default: any observer that depends on this value will be called during initialization of the element. For example, _requestOptionsChanged will be called automatically when an iron-ajax instance is created, because null is assigned to this.contentType. See: https://github.com/PolymerElements/iron-ajax/blob/content-type/iron-ajax.html#L267-L270

In the case of iron-ajax, I don't think this will cause a bug immediately, but we have generally avoided default null unless it's really necessary.

Does the value have to be null by default, or will it suffice for it to default to undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, but it looks like it prevents the _requestOptionsChanged observer from firing, because it's waiting for all arguments to be defined. As a result, the tests for auto fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yes, that's true. I guess null is the best alternative, then.

@cdata
Copy link
Contributor

cdata commented Jul 9, 2015

👍

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

2 participants