Skip to content

Commit

Permalink
Merge pull request #22 from pjvds/master
Browse files Browse the repository at this point in the history
Fix #18 cookie-parser populates req.cookies (plural)
  • Loading branch information
eXon committed May 18, 2016
2 parents 23725dd + 803d178 commit 5f418cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ function setRawCookie(rawCookie) {
function plugToRequest(req, res) {
if (req.cookie) {
_rawCookie = req.cookie;
} else if (req.cookies) {
_rawCookie = req.cookies;
} else if (req.headers && req.headers.cookie) {
setRawCookie(req.headers.cookie);
} else {
Expand Down
7 changes: 6 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ describe('ReactCookie', function() {
});

describe('plugToRequest', function() {
it('should load the request cookies', function() {
it('should load the request cookie', function() {
reactCookie.plugToRequest({ cookie: { test: 123 } });
expect(reactCookie.load('test')).toBe(123);
});

it('should load the request cookies', function() {
reactCookie.plugToRequest({ cookies: { test: 123 } });
expect(reactCookie.load('test')).toBe(123);
});

it('should load the raw cookie header', function() {
reactCookie.plugToRequest({ headers: { cookie: 'test=123' } });
Expand Down

0 comments on commit 5f418cd

Please sign in to comment.