Sha256: df0b8baf192af304a00f39479d64c686c924c6d6759b7312f9e4d137c12c233c

Contents?: true

Size: 894 Bytes

Versions: 32

Compression:

Stored size: 894 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/url_endpoint'

Async.run do
	endpoint = Async::HTTP::URLEndpoint.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

32 entries across 32 versions & 1 rubygems

Version Path
async-http-0.37.2 examples/upload/client.rb
async-http-0.37.1 examples/upload/client.rb
async-http-0.37.0 examples/upload/client.rb
async-http-0.36.3 examples/upload/client.rb
async-http-0.36.2 examples/upload/client.rb
async-http-0.36.1 examples/upload/client.rb
async-http-0.36.0 examples/upload/client.rb
async-http-0.35.1 examples/upload/client.rb
async-http-0.35.0 examples/upload/client.rb
async-http-0.34.4 examples/upload/client.rb
async-http-0.34.3 examples/upload/client.rb
async-http-0.34.2 examples/upload/client.rb