event-machine 内で Sinatra を使用しています。DELETE リクエストを受信したらサーバーをシャットダウンして終了し、200 OK を返したいと考えています。ただし、現在、私はその点に到達できず、終了する前に常に空の応答を返すことを終了します。どうすればこれを達成できますか?関連するコードは次のとおりです。
EM.run do
class Server < Sinatra::Base
delete '*' do
EM.defer proc{ halt 200 }, proc{ EM.stop }
end
end
Server.run!
end
何が起こるかというと、空の返信を受け取り、次のスタック トレースを取得します。
/Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/sinatra-1.3.3/lib/sinatra/base.rb:803:in `throw': uncaught throw `halt' in thread 0x7fa4225f2020 (ThreadError)
from /Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/sinatra-1.3.3/lib/sinatra/base.rb:803:in `halt'
from instant-markdown-d.rb:39:in `DELETE *'
from /Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/eventmachine-1.0.0/lib/eventmachine.rb:1037:in `call'
from /Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/eventmachine-1.0.0/lib/eventmachine.rb:1037:in `spawn_threadpool'
from /Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/eventmachine-1.0.0/lib/eventmachine.rb:1033:in `initialize'
from /Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/eventmachine-1.0.0/lib/eventmachine.rb:1033:in `new'
from /Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/eventmachine-1.0.0/lib/eventmachine.rb:1033:in `spawn_threadpool'
from /Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/eventmachine-1.0.0/lib/eventmachine.rb:1023:in `defer'
from /Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/thin-1.5.0/lib/thin/connection.rb:51:in `process'
from /Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/thin-1.5.0/lib/thin/connection.rb:39:in `receive_data'
from /Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
from /Users/syeo/.rvm/gems/ruby-1.8.7-p352@instant-markdown-d/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
from instant-markdown-d.rb:10
私も多くの同様の方法を試しましたが、200 を送信する方法が見つからず、サーバーをシャットダウンしました。