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 headers = preq.headers || {};
|
||||||
var multipart;
|
var multipart;
|
||||||
|
|
||||||
|
if (!headers.Accept && !headers.accept) {
|
||||||
|
headers.Accept = 'application/json';
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
xhr = new XMLHttpRequest(_sys);
|
xhr = new XMLHttpRequest(_sys);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
@ -1027,7 +1031,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data, err;
|
var data, err, resp;
|
||||||
if (xhr.status !== 200) {
|
if (xhr.status !== 200) {
|
||||||
err = new Error('bad status code: ' + xhr.status);
|
err = new Error('bad status code: ' + xhr.status);
|
||||||
}
|
}
|
||||||
|
@ -1050,12 +1054,19 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve({
|
resp = {
|
||||||
_request: xhr
|
_request: xhr
|
||||||
, headers: null // TODO
|
, headers: {}
|
||||||
, data: data
|
, data: data
|
||||||
, status: xhr.status
|
, 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 () {
|
xhr.ontimeout = function () {
|
||||||
var err = new Error('ETIMEDOUT');
|
var err = new Error('ETIMEDOUT');
|
||||||
|
|
Loading…
Reference in New Issue