【问题标题】:Getting rack error Rack::Lint::LintError: Status must be >=100 seen as integer获取机架错误 Rack::Lint::LintError: Status must be >=100 seen as integer
【发布时间】:2012-08-30 10:40:53
【问题描述】:

我正在尝试构建基于机架的 ruby​​ 应用程序,但我还是新手,我正在使用 ruby​​ 1.9.2 -p180

在我的 config.ru 文件中,我有:

require "rack"
require "./my_app.rb"
require "./auth.rb"

use Auth
run MyApp.new

现在中间件身份验证的主要问题,简单地说,如果请求的参数少于 2 个,我希望它不要继续 MyApp,而只是打印出一些东西(仅用于测试):

class Auth

  def initialize(app)
    @app = app
  end

  def call(env)     
    request = Rack::Request.new(env)
    if request.params.count < 2
        ["200",{"Content-Type" => "text/plain"}, ["Hello World"]]
        puts 'Working .. '
    else 
        @app.call(env)
    end
  end
end 

现在当我运行我的机架应用程序时:

rackup -s thin config.ru

并尝试得到结果:

curl http://localhost:9292/

我不断收到以下错误:

Rack::Lint::LintError: Status must be >=100 seen as integer
/Users/Apple/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.4.1/lib/rack/lint.rb:19:in `assert'
/Users/Apple/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.4.1/lib/rack/lint.rb:425:in `check_status'

当然,如果我在生产模式下运行它,我将不会收到此错误。

任何帮助将不胜感激。

【问题讨论】:

    标签: ruby-on-rails ruby rack middleware rack-middleware


    【解决方案1】:

    尝试使用整数作为状态:

    [200,{"Content-Type" => "text/plain"}, ["Hello World"]]
    

    代替:

    ["200",{"Content-Type" => "text/plain"}, ["Hello World"]]
    

    【讨论】:

      猜你喜欢
      • 2015-11-08
      • 2011-12-03
      • 2012-07-21
      • 1970-01-01
      • 2020-01-20
      • 1970-01-01
      • 2020-07-24
      • 1970-01-01
      • 2021-07-09
      相关资源
      最近更新 更多