Class: Net::HTTP

Inherits:
Protocol show all
Defined in:
lib/awsum/net_fix.rb

Instance Method Summary collapse

Instance Method Details

#request(req, body = nil, &block) ⇒ Object

Patched to handle 100-continue processing for S3



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/awsum/net_fix.rb', line 68

def request(req, body = nil, &block)  # :yield: +response+
  unless started?
    start {
      req['connection'] ||= 'close'
      return request(req, body, &block)
    }
  end
  if proxy_user()
    unless use_ssl?
      req.proxy_basic_auth proxy_user(), proxy_pass()
    end
  end

  req.set_body_internal body
  begin_transport req
    # Send only the headers if a 100-continue request
    limit = ((req.is_a?(Post) || req.is_a?(Put)) && req['expect'] == '100-continue') ? :headers : nil
    req.exec @socket, @curr_http_version, edit_path(req.path), limit
    begin
      res = HTTPResponse.read_new(@socket)
      if res.is_a?(HTTPContinue) && limit && req['content-length'].to_i > 0
        req.exec @socket, @curr_http_version, edit_path(req.path), :body
      end
    end while res.kind_of?(HTTPContinue)
    res.reading_body(@socket, req.response_body_permitted?) {
      yield res if block_given?
    }
  end_transport req, res

  res
end