Follow meta redirects and use the final URL when processing documents (#1568)

This commit is contained in:
Martynas Bagdonas 2018-10-04 10:24:39 +08:00 committed by Dan Stillman
parent a59ce2c343
commit ec5424d5ae
2 changed files with 68 additions and 2 deletions

View file

@ -29,6 +29,16 @@ describe("Zotero.HTTP", function () {
}
}
);
httpd.registerPathHandler(
'/test-redirect.html',
{
handle: function (request, response) {
response.setHeader("Content-Type", 'text/html', false);
response.setStatusLine(null, 200, "OK");
response.write("<html><head><meta http-equiv=\"refresh\" content=\"2;url=test.html\"/></head><body></body></html>");
}
}
);
});
after(function* () {
@ -68,6 +78,20 @@ describe("Zotero.HTTP", function () {
);
assert.isTrue(called);
});
it("should follow meta redirect for a document", async function () {
let url1 = `http://127.0.0.1:${port}/test-redirect.html`;
let url2 = `http://127.0.0.1:${port}/test.html`;
let called = false;
await Zotero.HTTP.processDocuments(
url1,
function (doc) {
assert.equal(doc.location.href, url2);
called = true;
}
);
assert.isTrue(called);
});
});
describe("#loadDocuments()", function () {