Ruby Eventmachine调用回调两次
我试图启动这个示例,但我在Ruby Eventmachine调用回调两次,ruby,eventmachine,Ruby,Eventmachine,我试图启动这个示例,但我在过程http\u请求方法中添加了简单的put。令我惊讶的是,当我从浏览器访问localhost:8080时,我在终端中看到了两次输出 为什么要打印两次?是虫子吗?也许我误解了eventmachine中的某些内容。 你可以看到我下面的例子 require 'eventmachine' require 'evma_httpserver' class MyHttpServer < EM::Connection include EM::HttpServer d
过程http\u请求
方法中添加了简单的put
。令我惊讶的是,当我从浏览器访问localhost:8080时,我在终端中看到了两次输出
为什么要打印两次?是虫子吗?也许我误解了eventmachine中的某些内容。
你可以看到我下面的例子
require 'eventmachine'
require 'evma_httpserver'
class MyHttpServer < EM::Connection
include EM::HttpServer
def post_init
super
no_environment_strings
end
def process_http_request
response = EM::DelegatedHttpResponse.new(self)
response.status = 200
response.content_type 'text/html'
response.content = '<center><h1>Hi there</h1></center>'
puts 'my_test_string'
response.send_response
end
end
EM.run do
EM.start_server '0.0.0.0', 8080, MyHttpServer
end
需要“eventmachine”
需要“evma_httpserver”
类MyHttpServer
第一个是对favicon的请求。第二个是对页面主体的请求。如果你想称之为bug,那是你的bug,而不是库的。哦,我应该打印出收到的数据,然后我会看到“get/favicon.ico”,但非常感谢:)