Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

Send proper outbound cookie header #398

Merged
merged 1 commit into from
Sep 29, 2017

Conversation

HaroldPutman
Copy link
Contributor

What this PR changes

crawler.cookies.getAsHeader() returns an array of strings with only the name/value pairs. The extra attributes of the cookie are not included.
When added to requestOptions.header.cookie the array of cookies is combined into a single string to avoid bugs in Node versions less than 8.

Rationale

Resolves issue #397

Outbound cookies should only include name and value in the header.
In Node.js versions < 8 if header.cookie is set to an array, the values a concatenated with commas which is wrong according to the specs. This was fixed in Node 8, but for compatibility if we join the cookie values and set header.cookie to a string it will always be right.

Outbound cookies should only include name and value in the header.
In Node.js versions < 8 if `header.cookie` is set to an array, the values a concatenated with commas which is wrong [according to the specs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie). This was [fixed in Node 8](nodejs/node#11259), but for compatibility if we join the cookie values and set `header.cookie` to a string it will always be right.

To avoid breakage, `crawler.cookies.getAsHeader()` still returns an array, but without the unexpected attributes. When it is added to request options it is joined into a semicolon-separated string.
Copy link
Member

@cgiffard cgiffard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for submitting a PR. I'll try and check this and get it out today.

@fredrikekelund fredrikekelund merged commit c0c7e48 into simplecrawler:master Sep 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants