4

Any request sent to a Rails controller gets an HTTP_ prefixed to it, as that's appended by ActionDispatch::HTTP.Headers. Is there a way to prevent that (without overriding ActionDispatch::HTTP, so that I can use my custom headers, as is and use those as keys for headers.@env?

4

1 回答 1

4

不,这是不可能的。这就是ActionDispatch::Http::Headers该类被设计为标准化标题的方式。

private

def env_name(key)
  key = key.to_s
  if key =~ HTTP_HEADER
    key = key.upcase.tr('-', '_')
    key = "HTTP_" + key unless CGI_VARIABLES.include?(key)
  end
  key
end

您仍然可以使用自定义标题。您只需要将它们引用为HTTP_X_FOO而不是x-foo.

于 2014-11-14T18:15:18.427 回答