usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
21.54k stars 1.01k forks source link

cURL import ignores cookies #1747

Open 2x2xplz opened 3 months ago

2x2xplz commented 3 months ago

When creating/importing a new request from a cURL command, the Cookie header is ignored -- it does not show up in the "headers" section of the new request, nor are the cookies & values specified by cURL added to Bruno's internal cookie store.

jwetzell commented 2 months ago

Can you provide an example of a curl command that does not import the cookies correctly. I just tested using a curl command that has the cookie header set in v1.12.3 and it appeared in the headers sections just fine.

2x2xplz commented 2 months ago

This is a random example. The curl command was generated by Firefox DevTools, Copy as cURL (POSIX). Every curl command produced this way has the same behavior, as far as I can tell.

curl 'https://www.target.com/' --compressed -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Connection: keep-alive' -H 'Cookie: TealeafAkaSid=fR6_sLKyA4MxlVNfSGjpWdnWyoCIwrg9; visitorId=018EC08C8FBD0201B21630993ECD7445; sapphire=1; ffsession={%22sessionHash%22:%2217130fa8c37b331712627429495%22%2C%22prevPageName%22:%22home%20page%22%2C%22prevPageType%22:%22home%20page%22%2C%22prevPageUrl%22:%22https://www.target.com/%22%2C%22sessionHit%22:1}; egsSessionId=0022a425-1815-4f93-ac9b-8b5b87b2e980; accessToken=eyJraWQiOiJlYXMyIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiI0ODE3MzljOC0wYTVjLTRhMTAtYjI0Ny1lZDI3ZWZlN2JlYWYiLCJpc3MiOiJNSTYiLCJleHAiOjE3MTI3MTM4MjUsImlhdCI6MTcxMjYyNzQyNSwianRpIjoiVEdULjdjZGFmYWIzNTMxOTQ5N2U5M2ZmYzdkMTEzMzZhYjc5LWwiLCJza3kiOiJlYXMyIiwic3V0IjoiRyIsImRpZCI6ImQ0ZjJmODY0NjVjMDJmYTcxYTEyODE2NzBjZjJhM2U5ZDExYzY2ODM3Zjc0Y2ViYjNjOTIzYzk5MGFjOTBmN2MiLCJzY28iOiJlY29tLm5vbmUsb3BlbmlkIiwiY2xpIjoiZWNvbS13ZWItMS4wLjAiLCJhc2wiOiJMIn0.dtrsgrtcaXZgAuKXesmFiE80xVRw5QzCFpnXJi7bfnbOBb7LyoaGWUMXN34sIBqS_RlydS3WjePyep3nXyez8PaBMbunwze6lwYpLVP1fJ-Zu6rqjzsmG9Uv_tkLOqvhMs7Q4WRHqatod8FV8j5YRN2sBPt_57PsoyNEWROExSzEXVpOaRr1Y1iq64UnxHW_OVZTcSfUsOuuhEOvofxr0U_f7UxF4LKPlDRLmZS7bY1wFFdjlsrd0Y_GpqsRgCcbbC1LWu9UG_kb9p8aftin4JVMQeKmGOZLSTejCw4M_veJAn1N_7zUhM9fOhTIiNDx_OfPbjv05oMrcDNRb9V2Mg; idToken=eyJhbGciOiJub25lIn0.eyJzdWIiOiI0ODE3MzljOC0wYTVjLTRhMTAtYjI0Ny1lZDI3ZWZlN2JlYWYiLCJpc3MiOiJNSTYiLCJleHAiOjE3MTI3MTM4MjUsImlhdCI6MTcxMjYyNzQyNSwiYXNzIjoiTCIsInN1dCI6IkciLCJjbGkiOiJlY29tLXdlYi0xLjAuMCIsInBybyI6eyJmbiI6bnVsbCwiZW0iOm51bGwsInBoIjpmYWxzZSwibGVkIjpudWxsLCJsdHkiOmZhbHNlLCJzdCI6Ik5WIn19.; refreshToken=O72twHoAQC26pvSsuCRIv5ESOSGp70SyYHKFT9yrnXzE9eFXn_N-0WXuj4BJJO0a5dtgIRH7j5S52m3MWvfHIQ; dteRfWys=LAL4kKO%2B; ci_pixmgr=other; mdLogger=false; kampyle_userid=b0e1-2727-bb1e-0f10-9ae5-3d30-81c6-1bd6; kampyleUserSession=1712627434308; kampyleSessionPageCounter=1; kampyleUserSessionsCount=1; kampyleUserPercentile=17.760506788554366; __gads=ID=7a00d18a8e655f54:T=1712627429:RT=1712627429:S=ALNI_MYhLoDeS5CP0_fi-XfuTxHKhNhwmw; __gpi=UID=00000dddaf61d317:T=1712627429:RT=1712627429:S=ALNI_MYPEV-SCqzhwQW_8xpxccjfKhmSsw; __eoi=ID=9f6cc66fb2eed4ab:T=1712627429:RT=1712627429:S=AA-Afjb25YHuQxRLwNnP2uy7g_8R' -H 'Upgrade-Insecure-Requests: 1' -H 'Sec-Fetch-Dest: document' -H 'Sec-Fetch-Mode: navigate' -H 'Sec-Fetch-Site: none' -H 'Sec-Fetch-User: ?1' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' -H 'TE: trailers'

When pasted in Bruno, no Cookie header is present: image

However Insomnia and Postman both generate a Cookie header:

image

image

jwetzell commented 2 months ago

Ok, I see the issue causing it not to appear in the headers. @helloanoop it looks like the Cookie headers is specifically skipped in some code here. This file goes to parse the cookies separately and attach them to the request object under cookies and cookieString but neither of those seem to make it to the UI. Is there any reason that the Cookie header should not be included with the headers?

2x2xplz commented 2 months ago

Is there any reason that the Cookie header should not be included with the headers?

One could make the argument that in some cases, cookies should be set dynamically, for example if running a test with 4 consecutive requests, you want the 2nd, 3rd, 4th request's cookies to be based on the Set-Cookie from previous responses. However I'd argue this should be an option in the UI and that the default behavior should simply be, if the user pastes a request with a cookie header that cookie header is included (just like every other header), unless the user specifically turns it off.