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

[Bug] Axios requests in pre-request scripts behave differently in bruno-app and bruno-cli #759

Closed
martinsefcik opened this issue Oct 24, 2023 · 2 comments · Fixed by #827

Comments

@martinsefcik
Copy link
Contributor

martinsefcik commented Oct 24, 2023

In pre-request script I use Axios requests which uses Axios feature that if content-type header is set to application/x-www-form-urlencoded and data is JS object then it is automatically serialized and encoded to urlencoded format. It is documented here: https://axios-http.com/docs/urlencoded#automatic-serialization and it should be available in Axios (if I'm not mistaken) from version 1.0.0

But it is working as expected only in bruno-app and not working correctly in bruno-cli (data object is sent serialized as json and not urlencoded)

Minimal request how to reproduce it:

meta {
  name: test
  type: http
  seq: 1
}

get {
  url: https://www.google.com
  body: none
  auth: none
}

script:pre-request {
  const axios = require('axios');
  let res = await axios({
    url: 'https://webhook.site/ce3d32c9-dbc1-42b5-8894-195beb0bdfea',
    method: 'post',
    data: {
      grant_type: 'client_credentials'
    },
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    }
  });
}

I can see on webhook.site that if such request is executed in bruno-app, then raw request body is:

grant_type=client_credentials

If I run this request in bruno-cli then the raw body is:

{
  "grant_type": "client_credentials"
}

bruno-app version: 0.27.0
buno-cli version: 0.15.1

@martinsefcik
Copy link
Contributor Author

martinsefcik commented Oct 24, 2023

It's strange, it is still working correctly also in 0.27.2 binary but if I run bruno-app from the latest sources then it is working incorrectly the same way as in bruno-cli.

@martinsefcik
Copy link
Contributor Author

martinsefcik commented Oct 30, 2023

It is caused by inconsistency in Axios versions used in bruno packages. Some of them uses ^1.5.1 and some of them ^0.26.0 and then there is axios.defaults.transformRequest function differently defined (with and without support for this automatic transformation of form url encoded data from object to string). If I updated Axios versions to ^1.5.1 in bruno-js and bruno-app then it starts working correctly in CLI and in App.

martinsefcik added a commit to martinsefcik/bruno that referenced this issue Oct 30, 2023
helloanoop added a commit that referenced this issue Nov 6, 2023
…tency

fix (#759): fixed axios versions inconsistency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant