跳至内容 跳至搜索

Action Dispatch PermissionsPolicy

配置 HTTP Feature-Policy 响应头,以指定当前文档及其 iframe 可以使用的浏览器功能。

示例全局策略

Rails.application.config.permissions_policy do |policy|
  policy.camera      :none
  policy.gyroscope   :none
  policy.microphone  :none
  policy.usb         :none
  policy.fullscreen  :self
  policy.payment     :self, "https://secure.example.com"
end

Feature-Policy 头已重命名为 Permissions-Policy。Permissions-Policy 需要不同的实现,并且尚未被所有浏览器支持。为了避免将来不得不重命名此中间件,我们使用新名称来命名中间件,但目前仍保留旧的标头名称和实现。

命名空间
方法
B
I
N

属性

[R] directives

类公共方法

new()

# File actionpack/lib/action_dispatch/http/permissions_policy.rb, line 113
def initialize
  @directives = {}
  yield self if block_given?
end

实例公共方法

build(context = nil)

# File actionpack/lib/action_dispatch/http/permissions_policy.rb, line 132
def build(context = nil)
  build_directives(context).compact.join("; ")
end

initialize_copy(other)

# File actionpack/lib/action_dispatch/http/permissions_policy.rb, line 118
def initialize_copy(other)
  @directives = other.directives.deep_dup
end