0
let headers = new Headers();

headers.append('Accept', '*/*');
headers.append('Content-Type', 'multipart/form-data');

let payload = await this.http.fetch(path, {
      method: 'post',
      body: item,
      headers: headers
    }).then(response => response.json())
      .catch(err => err);

I am creating this piece of code to post a file to the server. When making the request this converts the header from Content-Type to content-type, Accept to accept, and this is causing me problems, I am using Aurelia + TypeScript.

Any ideas to avoid this behavior?

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 2
    This is not related to `aurelia-fetch-client` but the `fetch` standard. It seems to be a known issue, see https://github.com/whatwg/fetch/issues/304 – Fabio Nov 29 '16 at 21:14
  • Have you tried `new Headers(Object.assign(HEADERS, {'Authorization': 'JWT ${token}'}))` as suggested in: http://stackoverflow.com/a/39726993/307 – Brett Veenstra Dec 02 '16 at 13:50
  • Also, header field-names are case-insensitive per https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2: "Field names are case-insensitive". The Github fetch client implementation (https://github.com/github/fetch) just converts non-string values to a String via: ` function normalizeValue(value) { if (typeof value !== 'string') { value = String(value) } return value }` – Brett Veenstra Dec 02 '16 at 14:59
  • Thanks for your reply! – Hugo UC SOSA Feb 02 '17 at 13:49

0 Answers0