class Cucumber::Formatter::IOHTTPBuffer
Attributes
headers[R]
method[R]
uri[R]
Public Class Methods
new(uri, method, headers = {}, https_verify_mode = nil, reporter = nil)
click to toggle source
# File lib/cucumber/formatter/http_io.rb, line 65 def initialize(uri, method, headers = {}, https_verify_mode = nil, reporter = nil) @uri = URI(uri) @method = method @headers = headers @write_io = Tempfile.new('cucumber', encoding: 'UTF-8') @https_verify_mode = https_verify_mode @reporter = reporter || NoReporter.new end
Public Instance Methods
close()
click to toggle source
# File lib/cucumber/formatter/http_io.rb, line 74 def close response = send_content(@uri, @method, @headers) @reporter.report(response.body) @write_io.close return if response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection) raise StandardError, "request to #{uri} failed with status #{response.code}" end
closed?()
click to toggle source
# File lib/cucumber/formatter/http_io.rb, line 90 def closed? @write_io.closed? end
flush()
click to toggle source
# File lib/cucumber/formatter/http_io.rb, line 86 def flush @write_io.flush end
write(data)
click to toggle source
# File lib/cucumber/formatter/http_io.rb, line 82 def write(data) @write_io.write(data) end
Private Instance Methods
build_client(uri, https_verify_mode)
click to toggle source
# File lib/cucumber/formatter/http_io.rb, line 137 def build_client(uri, https_verify_mode) http = Net::HTTP.new(uri.hostname, uri.port) if uri.scheme == 'https' http.use_ssl = true http.verify_mode = https_verify_mode if https_verify_mode end http end
build_request(uri, method, headers)
click to toggle source
# File lib/cucumber/formatter/http_io.rb, line 128 def build_request(uri, method, headers) method_class_name = "#{method[0].upcase}#{method[1..-1].downcase}" req = Net::HTTP.const_get(method_class_name).new(uri) headers.each do |header, value| req[header] = value end req end
send_content(uri, method, headers, attempt = 10)
click to toggle source
# File lib/cucumber/formatter/http_io.rb, line 96 def send_content(uri, method, headers, attempt = 10) content = (method == 'GET' ? StringIO.new : @write_io) http = build_client(uri, @https_verify_mode) raise StandardError, "request to #{uri} failed (too many redirections)" if attempt <= 0 req = build_request( uri, method, headers.merge( 'Content-Length' => content.size.to_s ) ) content.rewind req.body_stream = content begin response = http.request(req) rescue SystemCallError # We may get the redirect response before pushing the file. response = http.request(build_request(uri, method, headers)) end case response when Net::HTTPAccepted send_content(URI(response['Location']), 'PUT', {}, attempt - 1) if response['Location'] when Net::HTTPRedirection send_content(URI(response['Location']), method, headers, attempt - 1) end response end