Class | Net::HTTPGenericRequest |
In: |
lib/s33r/s33r_http.rb
|
Parent: | Object |
Modification of Net::HTTP base class to enable larger chunk sizes to be used when streaming data from large files.
N.B. does not alter the behaviour of this class unless you set chunk_size using the accessor.
chunk_size | [RW] | Size of chunks (in bytes) to send when streaming body data. |
Dump initial line and raw request headers (useful for visual debugging).
Switch on request debugging by passing :dump_requests => true to S33r::Client constructor.
# File lib/s33r/s33r_http.rb, line 40 40: def to_s 41: str = "*******\n" + 42: "#{self.class::METHOD} #{@path} HTTP/1.1\n" + 43: "Host: #{S33r::HOST}\n" 44: 45: self.each_capitalized do |key, value| 46: str += "#{key}: #{value}\n" 47: end 48: str += "*******\n\n" 49: str 50: end
Minor alterations to original source to enable variable chunk sizes.
# File lib/s33r/s33r_http.rb, line 54 54: def send_request_with_body_stream(sock, ver, path, f) # :doc: 55: raise ArgumentError, "Content-Length not given and Transfer-Encoding is not `chunked'" unless content_length() or chunked? 56: unless content_type() 57: warn 'net/http: warning: Content-Type did not set; using application/x-www-form-urlencoded' if $VERBOSE 58: set_content_type 'application/x-www-form-urlencoded' 59: end 60: @chunk_size ||= 1024 61: write_header sock, ver, path 62: if chunked? 63: while s = f.read(@chunk_size) 64: sock.write(sprintf("%x\r\n", s.length) << s << "\r\n") 65: end 66: sock.write "0\r\n\r\n" 67: else 68: while s = f.read(@chunk_size) 69: sock.write s 70: end 71: end 72: end