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