From f410f2b17129deeb8d2af166948885fe90029f91 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 8 Dec 2017 21:32:17 +0000 Subject: [PATCH] set Accept header and reply with headers --- oauth3.core.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/oauth3.core.js b/oauth3.core.js index 89b7fc9..e210c0a 100644 --- a/oauth3.core.js +++ b/oauth3.core.js @@ -1016,6 +1016,10 @@ var headers = preq.headers || {}; var multipart; + if (!headers.Accept && !headers.accept) { + headers.Accept = 'application/json'; + } + try { xhr = new XMLHttpRequest(_sys); } catch(e) { @@ -1027,7 +1031,7 @@ return; } - var data, err; + var data, err, resp; if (xhr.status !== 200) { err = new Error('bad status code: ' + xhr.status); } @@ -1050,12 +1054,19 @@ return; } - resolve({ + resp = { _request: xhr - , headers: null // TODO + , headers: {} , data: data , status: xhr.status + }; + (xhr.getAllResponseHeaders()||'').trim().split(/[\n\r]+/).forEach(function (line) { + var parts = line.split(': '); + var header = parts.shift(); + var value = parts.join(': '); + resp.headers[header] = value; }); + resolve(resp); }; xhr.ontimeout = function () { var err = new Error('ETIMEDOUT');