Kibana version:5.0.1
Elasticsearch version:5.0.1
Server OS version: Dev Environment, Redhat7
Browser version: Chrome 54 (64-bit)
Browser OS version: Chrome 54 (64-bit)
Original install method (e.g. download page, yum, from source, etc.): Source checkout
Description of the problem including expected versus actual behavior:
When trying to use the request.connection.iject (or server.inject) hapiJS functions to call another route from a Kibana plugin, the inject fails with the stacktrace given below, instead of successfully invoking the specified route. This appears to be because of a subtlety in how inject() works that the onRequest handler isn't expecting. The expected behaviour would be that the route is successfully invoked.
Steps to reproduce:
init(server, options) {
server.route({
path: '/my-plugin/route1',
method: 'GET',
handler(req, reply) {
reply ('HELLO ');
}
});
server.route({
path: '/my-plugin/route2',
method: 'GET',
handler(req, reply) {
req.connection.inject('/my-plugin/route1', function (origResp) {
reply (origResp.payload + 'World!');
});
}
});
},
Errors in browser console (if relevant): N/A
Provide logs and/or server output (if relevant):
server error [14:14:40.207] TypeError: Uncaught error: Cannot read property 'encrypted' of undefined
at /home/megan/analytics/kibana-plugins/kibana/src/server/http/setup_connection.js:51:27
at Items.serial (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/request.js:403:22)
at iterate (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/node_modules/items/lib/index.js:36:13)
at Object.exports.serial (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/node_modules/items/lib/index.js:39:9)
at _protect.run (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/request.js:398:15)
at internals.Protect.run (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/protect.js:64:5)
at internals.Request._invoke (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/request.js:396:19)
at internals.Request._execute (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/request.js:305:10)
at Domain.request._protect.enter (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/connection.js:261:25)
at Domain.run (domain.js:221:14)
at internals.Protect.enter (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/protect.js:80:17)
at /home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/connection.js:259:30
at req.prepare (/home/megan/analytics/kibana-plugins/kibana/node_modules/shot/lib/index.js:55:30)
at internals.Request.prepare (/home/megan/analytics/kibana-plugins/kibana/node_modules/shot/lib/request.js:96:16)
at Object.exports.inject (/home/megan/analytics/kibana-plugins/kibana/node_modules/shot/lib/index.js:55:16)
at internals.Connection.inject (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/connection.js:303:10)
This is preventing me from invoking multiple routes with my plugin to process the output as appropriate.
I _think_ this could be handled by a defensive check in handleRequest where it will pass the request on if there isn't a socket associated with it, similar to how it does if it's already an https request. Though I haven't tested such a theory yet
I think that's correct @meganwalker-ibm. Mind submitting an PR?
Working on it, seems to work as expected. Though having trouble getting the npm run test to pass even before I've made my one line change. But that's for a separate discussion :)
See PR #9332 @spalger