feat(utils): use req.cookies
if available instead of parsing
#2985
+179
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint
) & (yarn test
).For some frameworks,
req.cookies
is already a parsed object representing all the cookies on a request. A couple examples include any Node application deployed with Vercel, the Sails.js framework and any Express server which has the cookies middleware installed.I've simply modified the cookie logic to use
req.cookies
if it exists and to skip the parsing ofreq.headers.cookies
. For any application that doesn't have this available, the existing logic is used.In our case, we are deploying our Node applications through Vercel. Unfortunately the dynamic require line here ends up breaking inside of a Vercel deployment because the
cookies
dependency is missing (see 5.26.x behaviour vs 5.23.x behaviour in Vercel)We've notified Vercel of the issue but since the extra parsing here is unnecessary on ours and other similar deployments, I figured I would send this out to you guys! 😄
I noticed that the
extractNodeRequestData
method was entirely uncovered by tests. I've added tests for the specific cookie logic I introduced but also went ahead and added basic coverage for the rest of the properties that are parsed. I tried to keep the same structure and approach from your other tests but let me know if you'd like the tests rolled back to just the changes introduced here -- or would just like style changes in general.