Kong / insomnia

The open-source, cross-platform API client for GraphQL, REST, WebSockets, SSE and gRPC. With Cloud, Local and Git storage.
https://insomnia.rest
Apache License 2.0
33.72k stars 1.88k forks source link

Plugin setCookie sets only the last cookie #5026

Open mitchlloyd opened 1 year ago

mitchlloyd commented 1 year ago

Expected Behavior

In a plugin, calling context.request.setCookie would set multiple cookies:

module.exports.requestHooks = [(context) => {
  context.request.setCookie('first', 'first-value');
  context.request.setCookie('last', 'last-value');
}];

Expecting to see first=first-value; last=last-value in the request cookie header.

Actual Behavior

Instead I see last=last-value in the request cookie header.

Reproduction Steps

Add the plugin shown above. Make a request. Look at the cookie header value in Timeline tab.

Is there an existing issue for this?

Additional Information

I believe the error is here:

https://github.com/Kong/insomnia/blob/bbceb6097c855f93f93b69c85af680d85ae0ac57/packages/insomnia/src/main/network/libcurl-promise.ts#L195-L197

Unfortunately curl won't add multiple cookies like this. It wants the entire cookie string. From the man docs on cookie.

The data should be in the format "NAME1=VALUE1; NAME2=VALUE2

So I can probably hack around this issue by carefully constructing the "name" here.

I think it's worth mentioning that my particular use case would be much easier to handle if I could actually pass an arbitrary string value to the curl command for --cookie. I'd like to take advantage of setting an file name here:

If no '=' symbol is used in the argument, it is instead treated as a filename

However this may be a can of curl worms you don't want to open.

Insomnia Version

2022.4.2

What operating system are you using?

macOS

Operating System Version

macOS Monterey Version 12.4

Installation method

download from insomnia

Last Known Working Insomnia version

No response

aaronkampmeier commented 10 months ago

+1