PolymerElements / iron-ajax

Easily make ajax requests
https://www.webcomponents.org/element/PolymerElements/iron-ajax
127 stars 113 forks source link

iron-ajax sets custom headers only as Access-Control-Request-Headers values #317

Open dabukster opened 6 years ago

dabukster commented 6 years ago

Description

I'm using Polymer 2.0 and I want to set a custom header, like "x-personal-header": "some value"

<iron-ajax id="save" method="PUT" url="http://remotehost.net:9470/backend/resources/entities/Printer" body='{{currentItem}}'
      headers='{"access-control-allow-origin": "*"}' on-error="_handleError"
      handle-as="json" on-response="_handleResponse" debounce-duration="300"></iron-ajax>

Expected outcome

...other headers omitted...
x-personal-header: what

Actual outcome

...other headers omitted...
Access-Control-Request-Headers:x-personal-header

Steps to reproduce

  1. Put a iron-ajax element in the page and set headers headers='{"access-control-allow-origin": "*"}'
  2. Submit by clicking a button that invokes this.$.save.generateRequest()

Browsers Affected

robdawsonthales commented 6 years ago

@dabukster I was having this problem as well, turns out I needed to add an Access-Control-Allow-Headers header in the server response, like so:

Access-Control-Allow-Headers: *