Sha256: 8d842caf77f50b4ac9e082abd91fc3e5a252212b60a360f68aec99366151c271

Contents?: true

Size: 836 Bytes

Versions: 26

Compression:

Stored size: 836 Bytes

Contents

#!/usr/bin/env ruby
# 
# $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
# $LOAD_PATH.unshift(File.expand_path("../../http-protocol/lib", __dir__))

require 'async'
require 'async/logger'
require 'async/http/client'
require 'async/http/endpoint'

# Async.logger.level = Logger::DEBUG

Async.run do |task|
	endpoint = Async::HTTP::Endpoint.parse("https://www.google.com")
	
	client = Async::HTTP::Client.new(endpoint)
	
	headers = {
		'accept' => 'text/html',
	}
	
	request = Protocol::HTTP::Request.new(client.scheme, "www.google.com", "GET", "/search?q=cats", headers)
	
	puts "Sending request..."
	response = client.call(request)
	
	puts "Reading response status=#{response.status}..."
	
	if body = response.body
		while chunk = body.read
			puts chunk.size
		end
	end
	
	response.close
	
	puts "Finish reading response."
end

Version data entries

26 entries across 26 versions & 1 rubygems

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