workaround FreeBSD/OSX IO bug for large uploads
commitbbca687b8ce0c0cbf10407f2aaf87e18bfc311e5
authorAndrey Stikheev <andrey.stikheev@gmail.com>
Sun, 25 Oct 2009 10:11:35 +0000 (25 13:11 +0300)
committerEric Wong <normalperson@yhbt.net>
Sun, 25 Oct 2009 21:06:14 +0000 (25 14:06 -0700)
treed5af9c04bda396328d3dd47e65cdc69f227d3703
parent3a624fe924b8f3a9dfdcf5222ed6d1968f462468
workaround FreeBSD/OSX IO bug for large uploads

Under FreeBSD writing to the file in sync mode does not change current
position, so change position to the end of the file. Without this patch
multipart post requests with large data (image uploading) does not work
correctly:

  Status: 500 Internal Server Error
  bad content body
    /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/utils.rb:347:in `parse_multipart'
    /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/utils.rb:319:in `loop'
    /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/utils.rb:319:in `parse_multipart'

File position behavior under FreeBSD  :

ruby -v
ruby 1.8.7 (2009-04-08 patchlevel 160) [i386-freebsd7]

irb(main):001:0> b  = File.new("abc", "w+")
=> #<File:abc>
irb(main):002:0>  b.sync = true
=> true
irb(main):004:0> b.write("abc")
=> 3
irb(main):005:0> b.pos
=> 0

Acked-by: Eric Wong <normalperson@yhbt.net>
lib/unicorn/tee_input.rb