mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
add msg.payloadHandling for get requests
This commit is contained in:
committed by
GitHub
parent
14c362d4ba
commit
3ed5969e87
@@ -294,6 +294,18 @@ describe('HTTP Request Node', function() {
|
||||
url: req.originalUrl
|
||||
});
|
||||
})
|
||||
testApp.get('/getBodyParams', function(req,res) {
|
||||
// Either body-parser or express is discarding the body OR
|
||||
// GOT never sent a body. (there is nothing in params/query/body)
|
||||
// Oddly, if we set options.json (instead of options.body) in the GOT
|
||||
// request, then req.body will have the values!
|
||||
// Has the 21-httprequest node ever been able to send a payload in body
|
||||
// for a GET request?
|
||||
res.json({
|
||||
// body:JSON.parse(req.body),
|
||||
url: req.originalUrl
|
||||
});
|
||||
})
|
||||
testApp.get('/returnError/:code', function(req,res) {
|
||||
res.status(parseInt(req.params.code)).json({gotError:req.params.code});
|
||||
})
|
||||
@@ -1117,6 +1129,89 @@ describe('HTTP Request Node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow the payload to be sent in the body for a GET request', function(done) {
|
||||
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",paytoqs:"body",ret:"obj",url:getTestURL('/getBodyParams')},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(httpRequestNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
const payload = {a:"one",b:true,c:3}
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
// Either Express does not deliver the body of a GET request OR GOT doesn't send it!
|
||||
// That means we cannot test this! Oddly, if the HTTP-Req node sets options.json instead
|
||||
// of options.body, then the body is delivered.
|
||||
// msg.should.have.property('payload',{
|
||||
// body:payload,
|
||||
// url: '/getBodyParams'
|
||||
// });
|
||||
msg.should.have.property('payload').and.be.an.Object()
|
||||
msg.payload.should.have.property('url', '/getBodyParams')
|
||||
|
||||
msg.should.have.property('statusCode',200);
|
||||
msg.should.have.property('headers');
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
n1.receive({payload:payload});
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow the message to specify that the payload be append to querystring for a GET request', function(done) {
|
||||
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"use",ret:"obj",url:getTestURL('/getQueryParams')},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(httpRequestNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property('payload',{
|
||||
query:{a:'1',b:'2',c:'3'},
|
||||
url: '/getQueryParams?a=1&b=2&c=3'
|
||||
});
|
||||
msg.should.have.property('statusCode',200);
|
||||
msg.should.have.property('headers');
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
n1.receive({payload:{a:1,b:2,c:3},method:"get",payloadHandling:'query'});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should allow the message to specify that the payload be sent in the body for a GET request', function(done) {
|
||||
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"use",ret:"obj",url:getTestURL('/getBodyParams')},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(httpRequestNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
const payload = {a:"one",b:true,c:3}
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
// Either Express does not deliver the body of a GET request OR GOT doesn't send it!
|
||||
// That means we cannot test this! Oddly, if the HTTP-Req node sets options.json instead
|
||||
// of options.body, then the body is delivered.
|
||||
// msg.should.have.property('payload',{
|
||||
// payload: payload,
|
||||
// url: '/getBodyParams'
|
||||
// });
|
||||
msg.should.have.property('payload').and.be.an.Object()
|
||||
msg.payload.should.have.property('url', '/getBodyParams')
|
||||
msg.should.have.property('statusCode',200);
|
||||
msg.should.have.property('headers');
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
n1.receive({payload:payload,method:"get",payloadHandling:'body'});
|
||||
});
|
||||
});
|
||||
|
||||
it('should send a msg for non-2xx response status - 400', function(done) {
|
||||
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/returnError/400')},
|
||||
{id:"n2", type:"helper"}];
|
||||
|
Reference in New Issue
Block a user