Raw Post error going into mongrel:Error reading HTTP body: #

I am writing to an API that returns data in a callback as a raw POST
request. On it’s way into my rails controller, mongrel can’t read the
body of the request. A PHP routine inside Apache has no problem with
the request (which is Content-Type: Application/octet-stream). I can
read it in PHP like so:

$response = file_get_contents(‘php://input’);

But in ROR’s Mongrel server it never makes it to the ROR controller and
this happens:

Tue Apr 27 20:21:32 -0700 2010: Error reading HTTP body: #<RuntimeError:
Socket read return nil>
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/http_request.rb:105:in
read_socket' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/http_request.rb:77:in read_body’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/http_request.rb:55:in
initialize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:149:in new’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:149:in
process_client' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in run’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
initialize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in new’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in initialize’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
new' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in run’
/Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:34:in
run' /Users/lovell/Code/workspaces/Vidigami/vidigami/vendor/rails/railties/lib/commands/server.rb:111 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require’
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in require' ./script/server:3 /Library/Ruby/Gems/1.8/gems/ruby-debug-ide-0.4.9/lib/ruby-debug-ide.rb:109:in debug_load’
/Library/Ruby/Gems/1.8/gems/ruby-debug-ide-0.4.9/lib/ruby-debug-ide.rb:109:in
debug_program' /Library/Ruby/Gems/1.8/gems/ruby-debug-ide-0.4.9/bin/rdebug-ide:87 /usr/bin/rdebug-ide:19:in load’
/usr/bin/rdebug-ide:19

Mongrel can’t find the rest of the stream or has read past the end of
the stream prematurely. My “work around” is to have PHP page forward
the request like so:

$response = file_get_contents(‘php://input’);
$Curl_Session =
curl_init(“http://24.84.32.19:3000/facer/detect_result”);
curl_setopt ($Curl_Session, CURLOPT_POST, 1);
curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "Response=$response);
curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
curl_exec ($Curl_Session);
curl_close ($Curl_Session);

This is VERY UGLY. Is there something wrong in the mongrel server that
prevents it from dealing with this request? Or, is PHP much more
forgiving for poorly structured requests than Mongrel? I have no idea
if the callback request is poorly structured, but given that php has no
problem with it and that the API is used in a production environment, I
am more inclined to think the problem is in Mongrel somewhere.

Anyone?