Sha256: 3f22eeb00e7070260fe78de8f0863337b6b95c4a325c98dc05b4eeaaaa32d3b4

Contents?: true

Size: 887 Bytes

Versions: 26

Compression:

Stored size: 887 Bytes

Contents

#!/usr/bin/env ruby

$LOAD_PATH.unshift File.expand_path("../../lib", __dir__)

require 'async'
require 'async/http/body/file'
require 'async/http/body/delayed'
require 'async/http/client'
require 'async/http/endpoint'

Async.run do
	endpoint = Async::HTTP::Endpoint.parse("http://localhost:9222")
	client = Async::HTTP::Client.new(endpoint, Async::HTTP::Protocol::HTTP2)
	
	headers = [
		['accept', 'text/plain'],
	]
	
	body = Async::HTTP::Body::Delayed.new(Async::HTTP::Body::File.open("data.txt", block_size: 32))
	
	response = client.post(endpoint.path, headers, body)
	
	puts response.status
	
	# response.read -> string
	# response.each {|chunk| ...}
	# response.close (forcefully ignore data)
	# body = response.finish (read and buffer response)
	# response.save("echo.txt")
	
	response.each do |chunk|
		puts chunk.inspect
	end
	
ensure
	client.close if client
end

puts "Done."

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
async-http-0.48.2 examples/upload/client.rb
async-http-0.48.1 examples/upload/client.rb
async-http-0.48.0 examples/upload/client.rb
async-http-0.47.0 examples/upload/client.rb
async-http-0.46.5 examples/upload/client.rb
async-http-0.46.4 examples/upload/client.rb
async-http-0.46.3 examples/upload/client.rb
async-http-0.46.2 examples/upload/client.rb
async-http-0.46.1 examples/upload/client.rb
async-http-0.46.0 examples/upload/client.rb
async-http-0.45.9 examples/upload/client.rb
async-http-0.45.8 examples/upload/client.rb
async-http-0.45.7 examples/upload/client.rb
async-http-0.45.6 examples/upload/client.rb
async-http-0.45.4 examples/upload/client.rb
async-http-0.45.3 examples/upload/client.rb
async-http-0.45.2 examples/upload/client.rb
async-http-0.45.1 examples/upload/client.rb
async-http-0.45.0 examples/upload/client.rb
async-http-0.44.0 examples/upload/client.rb