Zotero.HTTP.request(): Process headers case insensitively
Using the Headers class from the Fetch API. Before, the added test would fail: `_requestInternal()`, not finding a header named `Content-Type` (case sensitive), would set it to `application/x-www-form-urlencoded`. XMLHttpRequest, upon being given both `content-type`: `application/json`) and `Content-Type`: `application/x-www-form-urlencoded`, would helpfully merge the two, producing `content-type`: `application/json, application/x-www-form-urlencoded`. That's obviously not the correct behavior.
This commit is contained in:
parent
e46ffaf84b
commit
fc8a037d12
2 changed files with 41 additions and 22 deletions
|
@ -45,6 +45,20 @@ describe("Zotero.HTTP", function () {
|
|||
}
|
||||
}
|
||||
);
|
||||
httpd.registerPathHandler(
|
||||
'/requireJSON',
|
||||
{
|
||||
handle(request, response) {
|
||||
if (request.getHeader('Content-Type') == 'application/json') {
|
||||
response.setStatusLine(null, 200, "OK");
|
||||
}
|
||||
else {
|
||||
response.setStatusLine(null, 400, "Bad Request");
|
||||
}
|
||||
response.write('JSON required');
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
@ -124,6 +138,20 @@ describe("Zotero.HTTP", function () {
|
|||
server.respond();
|
||||
});
|
||||
|
||||
it("should process headers case insensitively", async function () {
|
||||
Zotero.HTTP.mock = null;
|
||||
var req = await Zotero.HTTP.request(
|
||||
'GET',
|
||||
baseURL + 'requireJSON',
|
||||
{
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
}
|
||||
);
|
||||
assert.equal(req.status, 200);
|
||||
});
|
||||
|
||||
describe("Retries", function () {
|
||||
var spy;
|
||||
var delayStub;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue