这是indexloc提供的服务,不要输入任何密码
Skip to content

Document proper way to extract 'Set-Cookie' response headers #582

@rvolgers

Description

@rvolgers

The Set-Cookie header is special, it is not correct to combine multiple Set-Cookie headers into a single value separated by commas because it can change the semantics.

Reference:

I think the only correct way to parse this header with node-fetch is by using raw(). This is not at all obvious and should probably be documented.

Some (untested!) example code:

        if (cookieJar && res.headers.has('Set-Cookie')) {
            for (const [k, vv] of Object.entries(res.headers.raw())) {
                if (k.toLowerCase() === 'set-cookie') {
                    for (const v of vv) {
                        await promisify(cookieJar.setCookie)(v, url);
                    }
                }
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions