Skip to content

Commit

Permalink
Preserve fragment in responseUrl.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh committed Jan 12, 2024
1 parent 6585820 commit d8914f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -27,6 +27,7 @@ var preservedUrlFields = [
"protocol",
"query",
"search",
"hash",
];

// Create handlers that pass events from native requests
Expand Down
18 changes: 18 additions & 0 deletions test/test.js
Expand Up @@ -376,6 +376,24 @@ describe("follow-redirects", function () {
assert.equal(error.input, "/relative");
});

it("redirect to URL with fragment", function () {
app.get("/a", redirectsTo("/b#abc"));
app.get("/b", redirectsTo("/c#def"));
app.get("/c", redirectsTo("/d#ghi"));
app.get("/d", redirectsTo("/e#jkl"));
app.get("/e", redirectsTo("/f#mno"));
app.get("/f", sendsJson({ a: "b" }));

return server.start(app)
.then(asPromise(function (resolve, reject) {
http.get("http://localhost:3600/a", concatJson(resolve, reject)).on("error", reject);
}))
.then(function (res) {
assert.deepEqual(res.parsedJson, { a: "b" });
assert.deepEqual(res.responseUrl, "http://localhost:3600/f#mno");
});
});

it("should return with the original status code if the response does not contain a location header", function () {
app.get("/a", function (req, res) {
res.status(307).end();
Expand Down

0 comments on commit d8914f7

Please sign in to comment.