jschementi / iron

[Jimmy Schementi's development fork] Implementations of Python and Ruby programming languages for .NET Framework that are built on top of the Dynamic Language Runtime.
http://ironruby.net
17 stars 2 forks source link

rack.input is set improperly when no payload is present (e.g. GET), breaks Sinatra #28

Closed PlasticLizard closed 14 years ago

PlasticLizard commented 15 years ago

In IIS.cs, line 169, a StringIO is created using the raw value of request.Body. When there is no payload, however, this value is null. The result is a Errno:ESPIPE error, cleverly masked by a Method Not Found error raised agains NilClass when the 'pretty' method in Sinatra's showexceptions module tries to test either request.GET, request.POST or request.cookies for .empty? (I can't tell which is nil), preventing the normal Sinatra error message and aborting the thread. So, the critical error can be fixed by changing 169 in IIS.cs to

 SetEnv(env, "rack.input", new StringIO(MutableString.CreateMutable(request.Body ?? String.Empty, RubyEncoding.Default), IOMode.ReadOnly));

but there is another problem that is causing either GET, POST or cookies on Sinatras Request object to be nil, which obviously isn't expected. All that was required to fix that was to modify Sinatra's 'pretty' method in each of those cases to do a unless request.GET.nil? || request.GET.empty?, and so on, but I'm guessing those objects are always supposed to be populated somehow. My guess is the cookies, as I didn't see any explicit code in the IronRack stuff to deal with cookies, but who knows.

jschementi commented 15 years ago

request.Body should never be null, per the Rack spec: http://rack.rubyforge.org/doc/SPEC.html. When is their "no payload" returned by Sinatra?

PlasticLizard commented 15 years ago

Sorry, I wasn't clear - the "payload" I'm talking about is the Request - what gets passed to rack.input - on get requests, at least from my browsers, the Body property of your HttpRequest wrapper ends up being null, which means that the INPUT to Sinatra is a null rack.input - this is what causes all the havoc.

jschementi commented 14 years ago

Fixed in cc5bd360e4c55eba96b9d2fed5b605c041632651