如何使用 Rack 兼容应用程序设置多个 Access-Control-Allow-Origin
header 。
规范说我应该返回 [status, headers, body]
数组作为结果。 header 是 header 的散列:)。所以我不能设置相同的标题两次。
headers = {}
headers["Access-Control-Allow-Origin"] = "http://my.domain1.com"
headers["Access-Control-Allow-Origin"] = "http://my.domain2.com"
永远行不通。
我的情况应该怎么办?如何发送两个相同的 header ?
最佳答案
使用数组散列是很常见的,所以尝试:
headers = {
"Access-Control-Allow-Origin" => %w[
http://my.domain1.com
http://my.domain2.com
]
}
I've got a guess that it should be
{ "Access-Control-Allow-Origin" => [ 'a', 'b' ] * "\n" }
查看the RFC ,相关部分是“5.1 Access-Control-Allow-Origin Response Header ”,即 points to :
The Origin header field has the following syntax:
origin = "Origin:" OWS origin-list-or-null OWS
origin-list-or-null = %x6E %x75 %x6C %x6C / origin-list
origin-list = serialized-origin *( SP serialized-origin )
serialized-origin = scheme "://" host [ ":" port ]
; <scheme>, <host>, <port> from RFC 3986
那么,试试:
[ 'a', 'b' ] * ";"
或者,for the uninitiated :
%w[a b].join(';')
关于ruby - 使用 Rack (Access-Control-Allow-Origin) 发送两个相同的 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17528822/