What is the “env” variable in Rack middleware?

前端 未结 4 854
心在旅途
心在旅途 2021-01-01 11:56

I know a Rack middleware filter is a Ruby class with an initialize and a call method. I know the call method takes an \"env\" argument. Something like this:



        
4条回答
  •  情书的邮戳
    2021-01-01 12:20

    I suggest that you can try to print the 'env' variable with writing a simple programming.

    require "rubygems"
    require "rack" 
    def pp(hash)
      hash.map {|key,value| "#{key} => #{value}"}.sort.join("
    ") end Rack::Handler::WEBrick.run lambda {|env| [200,{},[pp(env)]]} , :Port=>3000

    enter the link localhost:3000

提交回复
热议问题