#114 ✓invalid
Greg Hazel

request.env.to_json fails

Reported by Greg Hazel | September 27th, 2009 @ 06:54 PM | in Future

This might not be the right place to file this bug, but using Thin I get an error:

request.env.to_json produces:

IOError (not opened for reading):
    /vendor/rails/activesupport/lib/active_support/json/encoders/enumerable.rb:10:in `each'
    /vendor/rails/activesupport/lib/active_support/json/encoders/enumerable.rb:10:in `map'
    /vendor/rails/activesupport/lib/active_support/json/encoders/enumerable.rb:10:in `to_json'

Upon inspection, the troublesome key seems to be: "rack.errors" => #<IO:0x3146ad8>

Is that really necessary?

Comments and changes to this ticket

  • macournoyer

    macournoyer September 28th, 2009 @ 10:18 AM

    • State changed from “new” to “invalid”

    rack.errors is set to STDERR. It's like doing STDERR.to_json

    I guess you could set rack.errors to nil before doing that or create another hash w/ only the keys you want, or do something like:

    request.env.keys.sort.inject({}) {|e,(k,v)| e[k] = v.to_s }.to_json
  • Greg Hazel

    Greg Hazel September 28th, 2009 @ 11:03 AM

    Isn't there a better place for than sort of variable than env? It would be neat it the environment was entirely made of strings, like a shell environment.

  • macournoyer

    macournoyer September 28th, 2009 @ 12:09 PM

    That's the Rack environment, nothing to do w/ shell env. Rack env is the
    only way to pass data around from request to response across apps and
    middlewares. Restricting to strings would be uselessly restrictive and
    degrade performance.

  • Greg Hazel

    Greg Hazel September 28th, 2009 @ 12:20 PM

    It is very related to the CGI environment variables, which have classically been strings since they were passed by the shell. The Rack parameters which are not strings have been conflated with the CGI parameters. This makes the hash difficult to serialize, when the rack variables should not be passed through a CGI-like interface.

    There are many options for improving this situation:

    1) Have "request.rack" separate from "request.env"

    2) Have "request.env['rack']" contain a hash of all the rack-related variables

    3) Have "request.env['cgi']" contain all the CGI-like environment variables

  • AlexWallis

    AlexWallis November 21st, 2020 @ 08:32 AM

    Fitness and lighthouse are pushed for the approach of the team for the candidates. The count of the light and precalculus help online is implied for the turns. Rush is anticipated for the width and Madoff the planted element for the changes for the citizens.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket