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
Version 2.50 introduced odd JSON behavior #1635
Comments
type ServerMessage struct {
Directory string `json:"directory"`
Filename string `json:"filename"`
Body string `json:"body"`
} |
@toddself are you sure this doesn't work with the latest version of request? 2.50 had a really nasty bug and you shouldn't use it. If the problem persists using the latest version, can you give me an example code that reproduces the bug (using |
It persists in 2.57.0 However, upon further examination this is mostly my fault! I was calling 'use strict';
var request = require('request');
module.exports = function(url, directory, filename, file, cb){
if(typeof cb !== 'function'){
cb = function(){};
}
var payload = JSON.stringify({
directory: directory,
filename: filename,
body: file
});
var opts = {
url: url,
body: payload,
json: true,
method: 'POST',
followRedirect: false
};
console.log('Sending to prompter', opts);
request(opts, function(err, res, body){
if(err || res.statusCode === 500){
err = err || new Error('Prompter returned a 500 '+body);
console.log('Unable to write to prompter ' + url, err);
return cb();
}
cb(null, res);
});
}; In 2.49.0 and lower though this worked even with my error. Apparently 2.50.0 fixes this issue. |
Yep, that might be the case. I think this change is related to #1310 where I fixed a previous change in that logic (not reverted). |
We are having a problem interacting with a server written in GO when we update request from 2.49.0 to 2.50.0. (This issue still exists in the latest 2.x release)
The issue is that the JSON being sent when
json: true
is set in the options is wrapped as a string.Here is a request body from v2.49.0:
Here is the same exact request body from v2.50.0
The latter causes the Go
json.Unmarshal
method to choke with:json: cannot unmarshal string into Go value of type main.ServerMessage
Looking through the changelog.md file the only change that seems to be relevant was the addition of an optional "reviver" -- however undoing that change doesn't seem to solve this problem.
The text was updated successfully, but these errors were encountered: