-
Notifications
You must be signed in to change notification settings - Fork 1.3k
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support for JSON merge-patch #1404
Comments
That |
Hey @kornelski you're right it is [EDIT] - Just realized |
After the discussion in |
Hey I finally got around to making a testcase for this issue. Here is the highlight: const request = require("superagent");
const express = require("express");
const bodyParser = require("body-parser");
// Create trivial express server to test with
const app = express();
app.use(bodyParser.json());
app.patch("/json-merge-patch", (req, res) => res.json({requestBody: req.body}));
app.post("/json-merge-patch", (req, res) => res.json({requestBody: req.body}));
if (require.main === module) {
app
.listen(3000, () => {
const runPost = () => request
.post("localhost:3000/json-merge-patch")
.send({data: "some data"}) // sends a JSON post body
.set("Content-Type", "application/json")
.set("Accept", "json")
.then(res => res.body);
const runPatch = () => request
.patch("localhost:3000/json-merge-patch")
.send({data: "some data"}) // sends a JSON post body
.set("Content-Type", "application/merge-patch+json")
.set("Accept", "json")
.then(res => res.body);
Promise.all([
runPost(),
runPatch(),
])
.then(([postBody, patchBody]) => {
console.log("[POST] returned JSON?", postBody);
console.log("[PATCH] returned JSON?", patchBody);
process.exit(JSON.stringify(postBody) === JSON.stringify(patchBody) ? 0 : 1);
});
});
} And when I run it:
|
Hey @deiga thanks for the hard work! I'm looking at the patch now, I'm going to go back and ensure that my test still works with the version you're using. [EDIT] - looks like my test is still failing on [EDIT2] - The only difference I can see is that you don't have the content type checks? My request looks like this:
For a second I thought the |
@t3hmrman Since this seems to only happen when using |
@deiga I just tested with
I think you can definitely close this, this must be an express bug. I thought I tested |
Just found out it's a My apologies @deiga thanks for looking at this |
It looks like super agent doesn't support JSON merge-patches with
Content-Type: application/merge-patch+json
. When I try tosend(...)
a JSON value it comes out on the other side empty:To reiterate, on the server side,
req.body
is actually empty.I haven't looked at the code but if I had to guess I'd gues sthat
send(..)
is doing some conversion stuff depending on whatContent-Type
is set to, which makes sense, but it would be nice in general if I could turn it off, or specify what the body is concretely to avoid this problem.The text was updated successfully, but these errors were encountered: