Sha256: 673f8e8c84b7b1ec34f36c67bef820de24b19f0f15b57014db3b1973fb5bae5d

Contents?: true

Size: 840 Bytes

Versions: 27

Compression:

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

# Async.logger.level = Logger::DEBUG

Async.run do |task|
	endpoint = Async::HTTP::URLEndpoint.parse("https://www.google.com")
	
	client = Async::HTTP::Client.new(endpoint)
	
	headers = {
		'accept' => 'text/html',
	}
	
	request = Async::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

27 entries across 27 versions & 1 rubygems

Version Path
async-http-0.40.3 examples/request.rb
async-http-0.40.2 examples/request.rb
async-http-0.40.1 examples/request.rb
async-http-0.40.0 examples/request.rb
async-http-0.39.0 examples/request.rb
async-http-0.38.3 examples/request.rb
async-http-0.38.2 examples/request.rb
async-http-0.38.1 examples/request.rb
async-http-0.38.0 examples/request.rb
async-http-0.37.14 examples/request.rb
async-http-0.37.13 examples/request.rb
async-http-0.37.12 examples/request.rb
async-http-0.37.11 examples/request.rb
async-http-0.37.10 examples/request.rb
async-http-0.37.9 examples/request.rb
async-http-0.37.7 examples/request.rb
async-http-0.37.6 examples/request.rb
async-http-0.37.5 examples/request.rb
async-http-0.37.4 examples/request.rb
async-http-0.37.3 examples/request.rb