Skip to content

Commit

Permalink
Add workaround for JRuby issue on Windows (JRUBY-6136)
Browse files Browse the repository at this point in the history
On Windows, calling File#size fails with an Unknown error (20047).
This workaround uses File#lstat instead.
  • Loading branch information
Thomas Hollstegge committed Mar 19, 2012
1 parent 0bdbda4 commit 767cd87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/httpclient/http.rb
Expand Up @@ -590,14 +590,14 @@ def add(part)
if Message.file?(part)
@as_stream = true
@body << part
if part.respond_to?(:size)
if part.respond_to?(:lstat)
@size += part.lstat.size
elsif part.respond_to?(:size)
if sz = part.size
@size += sz
else
@size = nil
end
elsif part.respond_to?(:lstat)
@size += part.lstat.size
else
# use chunked upload
@size = nil
Expand Down
13 changes: 13 additions & 0 deletions test/test_httpclient.rb
Expand Up @@ -649,6 +649,19 @@ def test_post_with_file
end
end

def test_post_with_file_without_size
STDOUT.sync = true
File.open(__FILE__) do |file|
def file.size
# Simulates some strange Windows behaviour
raise SystemCallError.new "Unknown Error (20047)"
end
assert_nothing_raised do
@client.post(serverurl + 'servlet', {1=>2, 3=>file})
end
end
end

def test_post_with_io # streaming, but not chunked
myio = StringIO.new("X" * (HTTP::Message::Body::DEFAULT_CHUNK_SIZE + 1))
def myio.read(*args)
Expand Down

0 comments on commit 767cd87

Please sign in to comment.