【问题标题】:Grape rails - get the uri from location where request has been sent fromGrape rails - 从发送请求的位置获取 uri
【发布时间】:2015-08-03 12:30:36
【问题描述】:

我有一个grape api + rails 和一个 rails 客户端。现在,在我的一个 API 端点中,我需要获取发送请求的客户端端点的 uri(不是 ip)路径,以确定我对此的响应,例如:

客户端从http://example.com/send/to/apihttp://myapi.com/my/api/endpoint发送请求。

所以在我的 api 端点中,我想获取http://example.com/send/to/api,对其进行测试并在主机为 example.com 时执行一些操作

如何在我的葡萄端点中获取请求的 uri?

【问题讨论】:

    标签: ruby-on-rails-4 grape


    【解决方案1】:

    在开始写这个问题后,我的朋友建议在发送请求时添加一个带有客户端 uri 的 X-Request-Origin 标头作为值。像 Oauth2 这样的 Gem 允许您 set headers

    然后在葡萄端点中,您可以使用返回客户端 uri 的request.headers["X-Request-Origin"] 获取值。

    只是把它放在这里,希望它可以节省其他人一些时间。 =)

    【讨论】:

      猜你喜欢
      • 2011-07-31
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 2021-09-18
      • 2011-03-06
      相关资源
      最近更新 更多