class Net::HTTPGenericRequest
Constants
- DEFAULT_LOCAL_READ_SIZE
Default size (in bytes) of the max read from a local source (File, String, etc.) to the user space write buffers for socket IO.
Public Class Methods
local_read_size=(readsize)
click to toggle source
# File lib/base/net_fix.rb, line 70 def self.local_read_size=(readsize) if(readsize <= 0) return end @@local_read_size = readsize end
local_read_size?()
click to toggle source
# File lib/base/net_fix.rb, line 77 def self.local_read_size?() @@local_read_size end
Private Instance Methods
send_request_with_body(sock, ver, path, body, send_only=nil)
click to toggle source
# File lib/base/net_fix.rb, line 93 def send_request_with_body(sock, ver, path, body, send_only=nil) self.content_length = body.respond_to?(:bytesize) ? body.bytesize : body.length delete 'Transfer-Encoding' supply_default_content_type write_header(sock, ver, path) unless send_only == :body sock.write(body && body.to_s) unless send_only == :header end
send_request_with_body_stream(sock, ver, path, f, send_only=nil)
click to toggle source
# File lib/base/net_fix.rb, line 101 def send_request_with_body_stream(sock, ver, path, f, send_only=nil) # KD: Fix 'content-length': it must not be greater than a piece of file left to be read. # Otherwise the connection may behave like crazy causing 4xx or 5xx responses # # Only do this helpful thing if the stream responds to :pos (it may be something # that responds to :read and :size but not :pos). if f.respond_to?(:pos) file_size = f.respond_to?(:lstat) ? f.lstat.size : f.size bytes_to_read = [ file_size - f.pos, self.content_length.to_i ].sort.first self.content_length = bytes_to_read end unless content_length() or chunked? raise ArgumentError, "Content-Length not given and Transfer-Encoding is not `chunked'" end bytes_to_read ||= content_length() supply_default_content_type write_header(sock, ver, path) unless send_only == :body unless send_only == :header if chunked? while s = f.read(@@local_read_size) sock.write(sprintf("%x\r\n", s.length) << s << "\r\n") end sock.write "0\r\n\r\n" else # KD: When we read/write over file EOF it sometimes make the connection unstable read_size = [ @@local_read_size, bytes_to_read ].sort.first while s = f.read(read_size) sock.write s # Make sure we do not read over EOF or more than expected content-length bytes_to_read -= read_size break if bytes_to_read <= 0 read_size = bytes_to_read if bytes_to_read < read_size end end end end