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

0.21.2 has a breaking change with pre-stringified JSON request body #4018

Closed
kawanet opened this issue Sep 5, 2021 · 2 comments · Fixed by #4020
Closed

0.21.2 has a breaking change with pre-stringified JSON request body #4018

kawanet opened this issue Sep 5, 2021 · 2 comments · Fixed by #4020

Comments

@kawanet
Copy link

kawanet commented Sep 5, 2021

Describe the bug

Since commit 5ad6994 in PR #3688 released with axios version 0.21.2,
it has a breaking change which forces to stringify the body even when pre-stringified in app.

To Reproduce

const axios = require("axios");
const body = "{}"; // pre-stringified JSON
const options = {headers: {"content-type": "application/json"}};
axios.post("http://127.0.0.1:3000/", body, options);
  • With 0.21.1, it sends a 2 byte request body {} to the server.
  • With 0.21.2, it sends a 4 byte request body "{}" to the server.

My app have a big post data which is already built by my app.
Axios should just send the body content pass through to the server.

Expected behavior

  • keep 0.21.1's behavior

Environment

  • Axios Version [e.g. 0.18.0]
  • Adapter [e.g. XHR/HTTP]
  • Browser [e.g. Chrome, Safari]
  • Browser Version [e.g. 22]
  • Node.js Version [e.g. 13.0.1]
  • OS: [e.g. iOS 12.1.0, OSX 10.13.4]
  • Additional Library Versions [e.g. React 16.7, React Native 0.58.0]

Additional context/Screenshots

  • Axios Version 0.21.1 and 0.21.2
  • Node.js Version 14.17.0
@kawanet
Copy link
Author

kawanet commented Sep 5, 2021

minimum server to listen:

const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json());
app.use((req, res) => res.send({body: req.body}));
app.listen(3000);

@kawanet
Copy link
Author

kawanet commented Sep 5, 2021

Thank you, @gfortaine! It fixes my app.

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.

2 participants