小编Rao*_*rma的帖子

ActionDispatch::Cookies 未在响应中设置 Set-Cookie 标头,但 response.set_cookie 会设置

我有一个仅限 Rails 5 API 的应用程序,想要在 JSON 请求的响应中发送 cookie。当我使用 ActionDispatch::Cookies 在请求的响应中设置 cookie 时,它​​不会Set-Cookie在响应中设置标头。虽然response.set_cookie确实有效。

我还在应用程序控制器中进行了钩子测试after_action,我看到Set-Cookieheader 不存在于 response.headers 中,但存在 cookies['name_of_cookie'] 。我还想问的一个问题是这些 cookie(ActionDispatch::Cookies) 何时设置响应头?它发生在机架中吗?

要求

  1. 我们想在 CORS 请求中设置 cookie。
  2. 我们想为所有来源设置 cookie

已经实施的内容

  1. 客户端发送请求withCredentials
  2. 在响应中Access-Control-Allow-Credentials: trueAccess-Control-Allow-Origin: <origin (request.headers['origin'])>存在
  3. 由于它是仅 Rails API 的应用程序,我们在应用程序中包含了以下中间件
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore, key: '_namespace_key'
Run Code Online (Sandbox Code Playgroud)

问题

  1. 为什么 ActionDispatch::Cookies 不起作用但 response.set_cookie 起作用?
  2. ActionDispatch::Cookies 何时在响应中设置标头?它是发生在afterRails 应用程序中的任何回调挂钩中,还是发生在机架中?因为直到after_action在 applicaton_controller 中标题才不存在。

奇怪的

  1. 在开发环境和我的本地计算机上它可以工作,但不能在生产环境中。是不是和domaincookie的设置有关系?我还在生产中使用 secure 和 httponly cookie,但在开发中仅使用 httponly。 …

ruby cookies ruby-on-rails actiondispatch rack-cors

6
推荐指数
1
解决办法
3463
查看次数

apt-get 更新时出现“NOSPLIT”(网络是否需要身份验证?)

每当我这样做时:

sudo apt-get 更新

我收到以下错误:

W: GPG error: http://ppa.launchpad.net/rael-gc/rvm/ubuntu xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 8094BB14F4E3FBBE
W: The repository 'http://ppa.launchpad.net/rael-gc/rvm/ubuntu xenial InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/xenial/InRelease  Clearsigned file isn't valid, got 'NOSPLIT' (does the network require authentication?)
E: Failed …
Run Code Online (Sandbox Code Playgroud)

ubuntu proxy networking apt

5
推荐指数
1
解决办法
2万
查看次数