我可以在 Loopback afterRemote hook 中得到响应 headers 吗?

Can I get to response headers in Loopback afterRemote hook?

我有一个环回模型,我正在使用 afterRemote 挂钩将请求记录到 keen.io。 http://docs.strongloop.com/display/public/LB/Remote+hooks#Remotehooks-ctx.result

我也在使用 response-time 包将响应时间 header 添加到响应中。 https://github.com/expressjs/response-time

这工作正常,希望我无法弄清楚如何到达响应中的 X-Response-Time header 以便将其记录到 keen.io。

我可以通过以下任何方式获得响应 header 吗?

module.exports = function(Studio) {
    var isStatic = true;
    var isNotStatic = false;
    Studio.disableRemoteMethod('deleteById', isStatic); // DELETE /Studios/{id}
    Studio.disableRemoteMethod('create', isStatic); // POST /Studios
    Studio.disableRemoteMethod('upsert', isStatic); // PUT /Studios
    Studio.disableRemoteMethod('updateAll', isStatic); // POST /Studios/update
    Studio.disableRemoteMethod('updateAttributes', isNotStatic); // PUT /Studios/{id}
    Studio.disableRemoteMethod('__create__ListenNps', isNotStatic);
    Studio.disableRemoteMethod('__delete__ListenNps', isNotStatic);
    Studio.disableRemoteMethod('__destroyById__ListenNps', isNotStatic);
    Studio.disableRemoteMethod('__updateById__ListenNps', isNotStatic);

    Studio.afterRemote('*', function(ctx, affectedModelInstance, next) {
        var Keen = require('keen-js');

        var client = new Keen({
            projectId: "myid",
            writeKey: "mykey"
        });

        var queryEvent = {
            ip: ctx.req.ip,
            baseUrl: ctx.req.baseUrl,
            url: ctx.req.url,
            route: ctx.req.route,
            query: ctx.req.query,
            method: ctx.methodString,
            // response: ctx.result.???, What can I do here to get to the response headers? Specifically X-Response-Time
            keen: {
                timestamp: new Date().toISOString()
            }
        };

        client.addEvent("queries", queryEvent, function(err, res) {
            if (err) {
                console.log(err)
            } else {
                console.log(res)
            }
        });
        next();
    });
};

尝试使用ctx.res.getHeader('X-Response-Time')method

收听 res.on('finish') event.