Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cookie support to CLI requests #2820

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matthewdickinson
Copy link

@matthewdickinson matthewdickinson commented Aug 13, 2024

Description

Right now, Bruno CLI doesn't support cookies. Many of our collections include an "Auth" request that we can use to get a auth cookie that will be used on subsequent requests. However, without cookies, we can't run the same collections (e.g. treat them as a test suite) without adding complicated pre-request scripts to fake the cookie first.

This adds a --use-cookies flag that (if set to true) creates a cookie store for this invocation of bru. Hence, no existing use-cases should be impacted, but this feature would be available for those who wish to use it.

This also should work in both standard and Proxy (HTTP or SOCKS) configurations.

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

@matthewdickinson matthewdickinson mentioned this pull request Aug 13, 2024
1 task
@sanjai0py sanjai0py requested a review from lohxt1 August 19, 2024 06:26
@helloanoop
Copy link
Contributor

Hey @matthewdickinson ! Thanks for taking time to work on this PR.

Just tested it. Implementation is working as expected.
But I worry about using a different approach than the one the GUI uses. I feel we should use the same approach in the interest of consistency.

Ref: https://github.com/usebruno/bruno/blob/main/packages/bruno-electron/src/utils/cookies.js

@nikischin
Copy link

Fully agree with @helloanoop

However, Please keep in mind that there are still bugs in our current cookie implementation in the app, just like #2682, #2950 or #1332 so I suppose while migrating the current app implementation to CLI, you might first want to address those possibly or as least beware that those functions are currently not working as expected and therefore also will not when migrated to CLI.

@matthewdickinson
Copy link
Author

I will see what I can do to change the implementation to be closer to the GUI's implementation. However, I only have time to look at this every few weeks, but I might not get back to it until the end of the month.

Thanks!

Copy link
Author

@matthewdickinson matthewdickinson left a comment

Choose a reason for hiding this comment

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

@helloanoop @nikischin Would you be willing to look at this again? I switched it to use the (exact) same logic as the Electron app.

It seems like the util could be centralized, but I left a question for you about that.

Copy link
Author

Choose a reason for hiding this comment

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

This is (almost) an exact copy of the util in the electron app, but I'm not sure where the mainainers would like to centralize this. bruno-common seems like it would make sense, but right now it doesn't seem to have any dependencies this this would require.

Comment on lines +79 to +91
const saveCookies = (url, headers) => {
let setCookieHeaders = [];
if (headers['set-cookie']) {
setCookieHeaders = Array.isArray(headers['set-cookie'])
? headers['set-cookie']
: [headers['set-cookie']];
for (let setCookieHeader of setCookieHeaders) {
if (typeof setCookieHeader === 'string' && setCookieHeader.length) {
addCookieToJar(setCookieHeader, url);
}
}
}
}
Copy link
Author

Choose a reason for hiding this comment

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

I coped this from packages/bruno-electron/src/ipc/network/index.js since it seemed like it could be centralized to this util once they both used the same util.

@nikischin
Copy link

@helloanoop @nikischin Would you be willing to look at this again? I switched it to use the (exact) same logic as the Electron app.

It seems like the util could be centralized, but I left a question for you about that.

Hi @matthewdickinson, thank you so much, I really appreciate that! I would be willing to test the cli, however, I haven't used the cli before and also I have no idea how to run the cli version of this branch and not the one installed with the latest version.

I would definitely benefit from this PR though, as if I want to use the cli in the future, I will definitely need this feature. Hope it gets merged soon! @lohxt1 is assigned for review :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants