summary refs log tree commit homepage
diff options
context:
space:
mode:
authorAndrey Stikheev <andrey.stikheev@gmail.com>2009-10-25 13:11:35 +0300
committerEric Wong <normalperson@yhbt.net>2009-10-25 14:06:14 -0700
commitbbca687b8ce0c0cbf10407f2aaf87e18bfc311e5 (patch)
treed5af9c04bda396328d3dd47e65cdc69f227d3703
parent3a624fe924b8f3a9dfdcf5222ed6d1968f462468 (diff)
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>
-rw-r--r--lib/unicorn/tee_input.rb1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb
index 188e2ea..7e77cdf 100644
--- a/lib/unicorn/tee_input.rb
+++ b/lib/unicorn/tee_input.rb
@@ -131,6 +131,7 @@ module Unicorn
         begin
           if parser.filter_body(dst, socket.readpartial(length, buf)).nil?
             @tmp.write(dst)
+            @tmp.seek(0, IO::SEEK_END) # workaround FreeBSD/OSX + MRI 1.8.x bug
             return dst
           end
         rescue EOFError