Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Avoid dupes while setting cookies #40

Merged
merged 2 commits into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/getHttpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export default function getHttpClient (options={}, req, res, httpClient=axios) {
// not in gsBeforeRoute for apps where that is an issue.
const mergedCookieString = merge(client.defaults.headers.cookie, cookieString);
const cookies = parse(mergedCookieString);
res.removeHeader("Set-Cookie");
cookies.forEach(cookie => {
res.cookie(cookie.name, cookie.value, cookie.options);
res.append("Set-Cookie", cookie.toString());
});

// Ensure that any subsequent requests are passing the cookies.
Expand Down
8 changes: 5 additions & 3 deletions test/lib/getHttpClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ describe("lib/getHttpClient", () => {

const mockServerResponse = {
removeHeader: sinon.spy(),
cookie: sinon.spy()
cookie: sinon.spy(),
append: sinon.spy()
};

const client = getHttpClient({}, req, mockServerResponse, axiosMock);
Expand All @@ -119,7 +120,7 @@ describe("lib/getHttpClient", () => {
}
});

expect(mockServerResponse.cookie.lastCall.args).to.deep.equal(["oh", "hai", {}]);
expect(mockServerResponse.append.lastCall.args).to.deep.equal(["Set-Cookie", "oh=hai"]);
});

it("should set default cookies on the axios instance", () => {
Expand All @@ -133,7 +134,8 @@ describe("lib/getHttpClient", () => {

const mockServerResponse = {
removeHeader: sinon.spy(),
cookie: sinon.spy()
cookie: sinon.spy(),
append: sinon.spy()
};

const client = getHttpClient({}, req, mockServerResponse, axiosMock);
Expand Down