set Accept header and reply with headers
This commit is contained in:
parent
a952ee6197
commit
f410f2b171
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue