Skip to content

Commit

Permalink
Do not send request with Transfer-Encoding: chuncked when IO respond …
Browse files Browse the repository at this point in the history
…to :size

1. There is no need to send query with Transfer-Encoding: chuncked when
   IO respond to :size.
2. Lighttpd does not support PUT, POST with Transfer-Encoding: chuncked.
   You will see that the lighty respond with 200 OK, but there is a file
   whose size is zero...

LIMITATION:
   timeout occurs certainly when you send very large file and @send_timeout is
   default since HTTPClient::Session#query() assumes that *all* write
   are finished in @send_timeout sec not each write.

WORKAROUND:
   increment @send_timeout and @receive_timeout or set @send_timeout and
   @receive_timeout to 0 not to be timeout.
  • Loading branch information
nabeken committed May 28, 2011
1 parent 1ffe2c8 commit 5d49093
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/httpclient.rb
Expand Up @@ -728,9 +728,9 @@ def trace(uri, *args, &block)
# a HTTP request message body.
#
# When you pass an IO as a body, HTTPClient sends it as a HTTP request with
# chunked encoding (Transfer-Encoding: chunked in HTTP header). Bear in mind
# that some server application does not support chunked request. At least
# cgi.rb does not support it.
# chunked encoding (Transfer-Encoding: chunked in HTTP header) if IO does not
# respond to :read. Bear in mind that some server application does not support
# chunked request. At least cgi.rb does not support it.
def request(method, uri, *args, &block)
query, body, header, follow_redirect = keyword_argument(args, :query, :body, :header, :follow_redirect)
if [:post, :put].include?(method)
Expand Down
24 changes: 15 additions & 9 deletions lib/httpclient/http.rb
Expand Up @@ -440,20 +440,26 @@ def init_response(body = nil)
# If no dev (the second argument) given, this method returns a dumped
# String.
def dump(header = '', dev = '')
file_block = Proc.new { |body|
buf = ''
reset_pos(body)
while !body.read(@chunk_size, buf).nil?
dev << buf
end
body.rewind
}
if @body.is_a?(Parts)
dev << header
buf = ''
@body.parts.each do |part|
if Message.file?(part)
reset_pos(part)
while !part.read(@chunk_size, buf).nil?
dev << buf
end
part.rewind
file_block.call(part)
else
dev << part
end
end
elsif Message.file?(@body)
dev << header
file_block.call(@body)
elsif @body
dev << header + @body
else
Expand Down Expand Up @@ -498,11 +504,11 @@ def content

def set_content(body, boundary = nil)
if body.respond_to?(:read)
# uses Transfer-Encoding: chunked. bear in mind that server may not
# support it. at least ruby's CGI doesn't.
# uses Transfer-Encoding: chunked if body does not respond to :size.
# bear in mind that server may not support it. at least ruby's CGI doesn't.
@body = body
remember_pos(@body)
@size = nil
@size = body.respond_to?(:size) ? body.size - body.pos : nil
elsif boundary and Message.multiparam_query?(body)
@body = build_query_multipart_str(body, boundary)
@size = @body.size
Expand Down

0 comments on commit 5d49093

Please sign in to comment.