views:

157

answers:

1

I am trying to perform a multipart post from one rails application to another using the following code:

require 'rest_client'
RestClient.post 'http://localhost:3000/users', { "user[fist_name]" => "foo", "user[profile_image]" => File.new('/test.png') })

My client app throws the time out exception and the server throws the exception shown below.

Fri Sep 18 13:39:31 -0700 2009: Error reading HTTP body: #<RuntimeError: Socket read returned insufficient data: 281>
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/http_request.rb:107:in `read_socket'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/http_request.rb:77:in `read_body'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/http_request.rb:55:in `initialize'

Rails server accepts multipart requests from browser and regular(non multipart) requests from client Rails app.

PS: I got the same exception when I used technoweenie_rest-client in my client app.

PPS: I am using Rails 2.3.2, ruby 1.8.6, Mongrel on Windows XP.

A: 

I think you have to increase the timeout on your server.

When you look at the source code:

    def read_socket(len)
      if [email protected]?
        data = @socket.read(len)
        if !data
          raise "Socket read return nil"
        elsif data.length != len
          raise "Socket read returned insufficient data: #{data.length}"
        else
          data
        end
      else
        raise "Socket already closed when reading."
      end
    end

You will see that this message comes from the validation if the contents-length is not equal to the posted-body-length in the post-header.

Lichtamberg
Client code waits for a long time before timing out. So how do set the read timeout for the server?
KandadaBoggu