简体   繁体   English

在Loopback.io远程方法中访问入站HTTP标头

[英]Access Inbound HTTP Headers in Loopback.io Remote Method

I have a remote method where I'm putting my application logic, as below: 我有一个远程方法,我将我的应用程序逻辑,如下所示:

module.exports = function(Entity) {
  HcpEntity.retrieveProfile = function(body, cb) {
    process.nextTick(function() {
      //TODO: Application Logic
    }
 }
}

And the corresponding model JSON snippet is: 相应的模型JSON片段是:

{
    "name": "HcpEntity",
    "base": "Model",
    "properties": {},
    "methods": {
        "retrieveProfile": {
            "isStatic" : true,
            "accepts": [
                {
                    "arg": "Request",
                    "type": "object",
                    "required": true,
                    "http": {
                        "source": "body"
                    }
                }
            ],
            "returns": {
                "arg": "Response",
                "type": "object"
            },
            "http": {
                "verb": "post"
            }
        }
    }
}

I need to be able to access the incoming HTTP headers in the area marked as //TODO: Application Logic so as to validate them. 我需要能够访问标记为//TODO: Application Logic的区域中的传入HTTP标头,以便验证它们。 Could someone please help. 请有人帮忙。

For the remote method accepts use - 对于远程方法accepts使用 -

accepts: [
    {arg: 'req', type: 'object', http: {source: 'req'}}
],

The request headers must be available in req.headers . 请求标头必须在req.headers可用。

See: https://loopback.io/doc/en/lb3/Remote-methods.html#http-mapping-of-input-arguments 请参阅: https//loopback.io/doc/en/lb3/Remote-methods.html#http-mapping-of-input-arguments

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM