FYI, tracking issue here:
http://github.com/jschementi/ironruby/issues/#issue/24

(I'm playing around with GitHub's issue tracking for current Silverlight and 
Rack work at the moment --- if any of these bugs are "keepers" they'll be moved 
to codeplex)

A fix will be in shortly, but that whole section needs some TLC.

~js
________________________________
From: ironruby-core-boun...@rubyforge.org [ironruby-core-boun...@rubyforge.org] 
on behalf of Philippe Monnet [ironr...@monnet-usa.com]
Sent: Saturday, September 12, 2009 10:07 AM
To: ironruby-core@rubyforge.org
Subject: [Ironruby-core] IronRuby Rack handling of POST-ed data

As I continued get my Camping app to work in IronRuby Rack, I noticed that I 
kept getting the following error when a form was POST-ed to the server:
[InvalidOperationException: can't convert System::String into String]
   Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame) 
+58
   Microsoft.Scripting.Interpreter.Interpreter.RunInstructions(InterpretedFrame 
frame) +90
   Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) +278
   Microsoft.Scripting.Interpreter.LightLambda.Run2(T0 arg0, T1 arg1) +341
   IronRuby.Runtime.RubyScriptCode.Run(Scope scope, Boolean bindGlobals) +293
   IronRuby.Runtime.RubyScriptCode.Run(Scope scope) +39
   Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink) +138
   Microsoft.Scripting.SourceUnit.Execute(Scope scope) +43
   Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope) +75
   IronCamping.RubyEngine.Execute(String code, ScriptScope aScope) in 
E:\DEV\POC\IronCamping\IronCamping\RubyEngine.cs:56
   IronCamping.IIS.Handle(Request request, Response response) in 
E:\DEV\POC\IronCamping\IronCamping\IIS.cs:177
   IronCamping.HttpHandler.ProcessRequest(HttpContext context) in 
E:\DEV\POC\IronCamping\IronCamping\HttpHandler.cs:41
   
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
 +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& 
completedSynchronously) +75
As a work-around I found that if I explictly passed the request.Body as a 
string using the following code to set the rack.input environment variable in 
the Handle mthod of IIS class, the issue went away:

if (request.Body != null)
{
        // Explicitly pass the request body as a string
        string myInput = request.Body.ToString();
        handle_scope.SetVariable("__myinput", myInput);
        env["rack.input"] = RubyEngine.Execute("StringIO.new(__myinput.to_s)", 
handle_scope);
}
else
{
        // Original code
        env["rack.input"] = RubyEngine.Execute("StringIO.new(__request.body || 
'')", handle_scope);

}


(Original code in GitHub: 
http://github.com/ironruby/ironruby/blob/adb33b18780e5f2a7e050fd38ebc58750ec1cf5b/Merlin/Main/Hosts/IronRuby.Rack/IIS.cs)

Is this the right way to go?

Philippe
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to