Sha256: 3ad057f30c59e824c4a1b043efd745ff3e312018be450063fa09dc3b2301b0d1

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require 'net/http'

# overrides for the default Net::HTTP classes

# add some convenience functions for checking response status
class Net::HTTPResponse
  attr_accessor :success

  def ok?
    success
  end

  def success
    response.is_a?(Net::HTTPOK)
  end

  def not_found
    response.is_a?(Net::HTTPNotFound)
  end

  def to_s
    body
  end
end

# modified to enable larger chunk sizes to be used
# when streaming data from large files
class Net::HTTPGenericRequest
  attr_accessor :chunk_size

  private
  def send_request_with_body_stream(sock, ver, path, f)
    raise ArgumentError, "Content-Length not given and Transfer-Encoding is not `chunked'" unless content_length() or chunked?
    unless content_type()
      warn 'net/http: warning: Content-Type did not set; using application/x-www-form-urlencoded' if $VERBOSE
      set_content_type 'application/x-www-form-urlencoded'
    end
    @chunk_size ||= 1024
    write_header sock, ver, path
    if chunked?
      while s = f.read(@chunk_size)
        sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
      end
      sock.write "0\r\n\r\n"
    else
      while s = f.read(@chunk_size)
        sock.write s
      end
    end
  end
end

class Net::HTTPRequest
  def to_s
    str = "*******\n" +
    "#{self.class::METHOD} #{@path} HTTP/1.1\n" +
    "Host: #{S3::HOST}\n"
    
    self.each_capitalized do |key, value|
      str += "#{key}: #{value}\n"
    end
    str += "*******\n\n"
    str
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
s33r-0.2 lib/s33r/net_http_overrides.rb