使用 Sinatra、Thin、Rails 和 Rack::Cascade 时出现 Rack::Session:Cookie 错误

发布于 2024-08-20 13:10:25 字数 2244 浏览 2 评论 0原文

我有一个组合的 Sinatra/Rails 应用程序,它使用 Rack::Session::Cookie 共享会话。当使用Rack::Handler::Thin.run app启动时,应用程序工作正常,但如果rackup文件以thin start启动,我会在Rack中收到错误: :Session::Cookie:


!! Unexpected error while processing request: no marshal_dump is defined for class Proc
no marshal_dump is defined for class Proc
 /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/session/cookie.rb:64:in `dump'
 /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/session/cookie.rb:64:in `commit_session'
 /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/session/cookie.rb:38:in `call'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/connection.rb:76:in `block in pre_process'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/connection.rb:74:in `catch'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/connection.rb:74:in `pre_process'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/connection.rb:57:in `process'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/connection.rb:42:in `receive_data'
 /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
 /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/backends/base.rb:57:in `start'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/server.rb:156:in `start'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/controllers/controller.rb:80:in `start'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/runner.rb:177:in `run_command'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/runner.rb:143:in `run!'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/bin/thin:6:in `'

rackup 文件如下所示:


require ::File::dirname(__FILE__) + '/config/environment'
require 'thin'

app = Rack::Builder.new {
  use Rails::Rack::Static
  run Rack::Cascade.new([Sinatra::Application, ActionController::Dispatcher.new])
}.to_app

use Rack::Session::Cookie, :key => '_example', :domain => 'example.org',
  :secret => 'secret'

# have to use this
Rack::Handler::Thin.run app, :Port => 4000, :Host => "0.0.0.0"
# want to use: run app

I have a combined Sinatra/Rails app that shares a session using Rack::Session::Cookie. The app works fine when started with Rack::Handler::Thin.run app, but if the rackup file is start with thin start, I get an error in Rack::Session::Cookie:


!! Unexpected error while processing request: no marshal_dump is defined for class Proc
no marshal_dump is defined for class Proc
 /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/session/cookie.rb:64:in `dump'
 /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/session/cookie.rb:64:in `commit_session'
 /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/session/cookie.rb:38:in `call'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/connection.rb:76:in `block in pre_process'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/connection.rb:74:in `catch'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/connection.rb:74:in `pre_process'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/connection.rb:57:in `process'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/connection.rb:42:in `receive_data'
 /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
 /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/backends/base.rb:57:in `start'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/server.rb:156:in `start'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/controllers/controller.rb:80:in `start'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/runner.rb:177:in `run_command'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/lib/thin/runner.rb:143:in `run!'
 /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.5/bin/thin:6:in `'

The rackup file looks like this:


require ::File::dirname(__FILE__) + '/config/environment'
require 'thin'

app = Rack::Builder.new {
  use Rails::Rack::Static
  run Rack::Cascade.new([Sinatra::Application, ActionController::Dispatcher.new])
}.to_app

use Rack::Session::Cookie, :key => '_example', :domain => 'example.org',
  :secret => 'secret'

# have to use this
Rack::Handler::Thin.run app, :Port => 4000, :Host => "0.0.0.0"
# want to use: run app

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

‘画卷フ 2024-08-27 13:10:25

您是否尝试过这样的操作:

app = Rack::Builder.new {
  use Rack::Session::Cookie, :key => '_example', :domain => 'example.org', :secret => 'secret'
  use Rails::Rack::Static
  run Rack::Cascade.new([Sinatra::Application, ActionController::Dispatcher.new])
}.to_app

看起来您的问题是您在 app 之外使用 Rack::Session::Cookie。

Have you tried something like this:

app = Rack::Builder.new {
  use Rack::Session::Cookie, :key => '_example', :domain => 'example.org', :secret => 'secret'
  use Rails::Rack::Static
  run Rack::Cascade.new([Sinatra::Application, ActionController::Dispatcher.new])
}.to_app

Looks like your problem is that you're using Rack::Session::Cookie outside of app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文