Sha256: 808ab2cead32f490f745892ea540296695325564f8eb03b17cccded2560eacd4

Contents?: true

Size: 883 Bytes

Versions: 28

Compression:

Stored size: 883 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 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

28 entries across 28 versions & 1 rubygems

Version Path
async-http-0.52.4 examples/upload/client.rb
async-http-0.52.3 examples/upload/client.rb
async-http-0.52.2 examples/upload/client.rb
async-http-0.52.1 examples/upload/client.rb
async-http-0.52.0 examples/upload/client.rb
async-http-0.51.6 examples/upload/client.rb
async-http-0.51.5 examples/upload/client.rb
async-http-0.51.4 examples/upload/client.rb
async-http-0.51.3 examples/upload/client.rb
async-http-0.51.2 examples/upload/client.rb
async-http-0.51.1 examples/upload/client.rb
async-http-0.51.0 examples/upload/client.rb
async-http-0.50.13 examples/upload/client.rb
async-http-0.50.12 examples/upload/client.rb
async-http-0.50.11 examples/upload/client.rb
async-http-0.50.10 examples/upload/client.rb
async-http-0.50.9 examples/upload/client.rb
async-http-0.50.8 examples/upload/client.rb
async-http-0.50.7 examples/upload/client.rb
async-http-0.50.6 examples/upload/client.rb