googlearchive / core-ajax

Polymer Core Ajax
26 stars 52 forks source link

headers set but not sent #92

Open revgum opened 9 years ago

revgum commented 9 years ago

Headers passed into the core-ajax element are being set as the prototype properties with Object.create(...).

get requestHeaders() {
  var headers = Object.create(this.headers || {});

  if (!('content-type' in headers)) {
    headers['content-type'] = this.contentType;
  }

  return headers;
},

Then in core-request, those headers aren't surfacing as part of the xhr.setRequestHeader...

It seems like a good fix would be getPrototypeOf before inspecting and setting the content-type key. I've tested this and the result is a fully populated headers object that core-request handles properly.

get requestHeaders() {
  var headers = Object.create(this.headers || {});
  headers = Object.getPrototypeOf(headers);

  if (!('content-type' in headers)) {
    headers['content-type'] = this.contentType;
  }

  return headers;
},
Tudmotu commented 9 years ago

Why not simply var headers = this.headers || {}?

jlg7 commented 9 years ago

:+1: please also apply patch to "https://github.com/PolymerElements/iron-ajax" if that is the perceived future!