无法仅使用Safari加载资源401

时间:2014-10-13 07:15:21

标签: ruby-on-rails devise safari unauthorized

我的应用程序中发现了一个有趣的问题。

我正在使用带有ruby 2.0的Rails 3。我已经有一台运行我的应用程序的生产服务器和另一台登台服务器。我正在配置一个新的更好的,但我只有Safari的问题。

Redirected to http://ip.server/
Completed 302 Found in 201.7ms (ActiveRecord: 0.0ms)
Started GET "/" for my.ip at 2014-10-13 08:17:18 +0200
Processing by DashboardController#index as HTML
Completed 401 Unauthorized in 1.2ms
Started GET "/user/sign_in" for my.ip at 2014-10-13 08:17:18 +0200
Processing by Devise::SessionsController#new as HTML
  Rendered application/_field_errors.html.erb (0.0ms)
  Rendered application/_field_errors.html.erb (0.0ms)
  Rendered devise/sessions/new.html.erb within layouts/devise (2.3ms)
Completed 200 OK in 5.5ms (Views: 3.8ms | ActiveRecord: 0.0ms)

当我查看网络标签时,我可以看到:

无法加载资源:服务器响应状态为401(未授权)

一开始我认为我的问题来自Devise,但后来我检查了Google并发现: cross browser problem

我尝试使用Chrome,但它确实有用。我也试过没有AdBlock或私人导航但它仍然无法使用Safari。

修改

我做了2个请求,一个来自Chrome,第二个来自Safari。唯一的区别是这一行:

WARNING: Can't verify CSRF token authenticity

编辑2:

我在protect_from_forgery上评论了行ApplicationController.rb,最后这个错误(关于CSRF)不对我的问题负责。

当我尝试使用Chrome和Safari时,我会堆叠。

使用Chrome:

Started POST "/user/sign_in" for my.ip at 2014-10-14 13:27:51 +0200
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"c86MNR4MCSbQWJiAjkGtgfgPMg5YirG1tqf/2vqdBWc=", "user"=>{"email"=>"test@example.com", "password"=>"[FILTERED]", "remember_me"=>"0"}}
User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`email` = 'test@example.com' LIMIT 1
(0.1ms)  BEGIN
WARNING: User#current is nil, are you including SentientController on your ApplicationController?
(0.3ms)  UPDATE `users` SET `last_sign_in_at` = '2014-10-14 11:26:45', `current_sign_in_at` = '2014-10-14 11:27:51', `sign_in_count` = 52, `updated_at` = '2014-10-14 11:27:51' WHERE `users`.`type` IN ('User::Admin') AND `users`.`id` = 1
(26.1ms)  COMMIT
Redirected to http://server.ip/
Completed 302 Found in 135.6ms (ActiveRecord: 0.0ms)
Started GET "/" for my.ip at 2014-10-14 13:27:51 +0200
Processing by DashboardController#index as HTML
User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
server.ip  Rendered dashboard/index.html.erb within layouts/application (2.5ms)
Rendered application/_header.html.slim (57.6ms)
Rendered application/_sidebar.html.erb (48.1ms)
Rendered application/_page_header.html.slim (2.0ms)
Rendered application/_flash_messages.html.erb (0.5ms)
Rendered application/_footer.html.erb (0.8ms)
Completed 200 OK in 137.5ms (Views: 122.9ms | ActiveRecord: 5.1ms)

使用Safari:

Started POST "/user/sign_in" for my.ip at 2014-10-14 13:27:58 +0200
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"TWKhSxus5q46H9sZdEvMnzD52r0zA5phw/Pv7K+NKuY=", "user"=>{"email"=>"test@example.com", "password"=>"[FILTERED]", "remember_me"=>"0"}}
User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`email` = 'test@example.com' LIMIT 1
(0.1ms)  BEGIN
(0.3ms)  UPDATE `users` SET `last_sign_in_at` = '2014-10-14 11:27:51', `current_sign_in_at` = '2014-10-14 11:27:58', `sign_in_count` = 53, `updated_at` = '2014-10-14 11:27:58' WHERE `users`.`type` IN ('User::Admin') AND `users`.`id` = 1
(24.8ms)  COMMIT
Redirected to http://server.ip/
Completed 302 Found in 138.2ms (ActiveRecord: 0.0ms)
Started GET "/" for my.ip at 2014-10-14 13:27:58 +0200
Processing by DashboardController#index as HTML
Completed 401 Unauthorized in 1.2ms
Started GET "/user/sign_in" for my.ip at 2014-10-14 13:27:58 +0200
Processing by Devise::SessionsController#new as HTML
Rendered application/_field_errors.html.erb (0.0ms)
Rendered application/_field_errors.html.erb (0.0ms)
Rendered devise/sessions/new.html.erb within layouts/devise (2.2ms)
Completed 200 OK in 5.2ms (Views: 3.7ms | ActiveRecord: 0.0ms)

1 个答案:

答案 0 :(得分:0)

问题解决了。它根本不是来自我的应用程序,而是来自我的DNS重定向。我为测试放了一个简单的Web重定向,我忘了添加DNS重定向。

现在一切都运转良好。

我希望这能帮助别人!