Skip to content

Commit

Permalink
Cors origin handler missing vary. Closes hapijs#1163
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Nov 20, 2013
1 parent 417b600 commit 83ce09e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/response/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ exports.cors = function (response, request) {
if (cors._origin.any) {
response.header('access-control-allow-origin', '*');
}
else if (internals.matchOrigin(request.headers.origin, cors)) {
else {
response.header('vary', 'origin', true);
response.header('access-control-allow-origin', request.headers.origin);
}
else if (cors._origin.qualifiedString && cors.isOriginExposed) {
response.header('access-control-allow-origin', cors._origin.qualifiedString);

if (internals.matchOrigin(request.headers.origin, cors)) {
response.header('access-control-allow-origin', request.headers.origin);
}
else if (cors._origin.qualifiedString && cors.isOriginExposed) {
response.header('access-control-allow-origin', cors._origin.qualifiedString);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions test/integration/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('Response', function () {
expect(res.result).to.exist;
expect(res.result).to.equal('ok');
expect(res.headers['access-control-allow-origin']).to.not.exist;
expect(res.headers.vary).to.equal('origin');
done();
});
});
Expand Down

0 comments on commit 83ce09e

Please sign in to comment.