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

**URL:** <https://www.ruby-forum.com/t/raw-post-error-going-into-mongrel-error-reading-http-body/187711>\
**Category:** Mongrel\
**Created:** [April 28, 2010, 5:40am UTC](https://www.ruby-forum.com/t/raw-post-error-going-into-mongrel-error-reading-http-body/187711 "2010-04-28T05:40:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![robblovell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@robblovell](https://www.ruby-forum.com/u/robblovell)\
**Post date:** [April 28, 2010, 5:40am UTC](https://www.ruby-forum.com/t/raw-post-error-going-into-mongrel-error-reading-http-body/187711/1 "2010-04-28T05:40:52Z")

</div>

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](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?
