Sha256: 33607260b9fe8edf52b019bce1b2ef10e7628810691aacd63d0a99d335f414fd

Contents?: true

Size: 965 Bytes

Versions: 11

Compression:

Stored size: 965 Bytes

Contents

$LOAD_PATH.unshift File.expand_path("../../lib", __dir__)

require 'async'
require 'async/io/stream'
require 'async/http/url_endpoint'
require 'http/protocol/http1/connection'
require 'pry'

Async.run do
	endpoint = Async::HTTP::URLEndpoint.parse("https://www.google.com/search?q=kittens", alpn_protocols: ["http/1.1"])
	
	peer = endpoint.connect
	
	puts "Connected to #{peer} #{peer.remote_address.inspect}"
	
	# IO Buffering...
	stream = Async::IO::Stream.new(peer)
	client = HTTP::Protocol::HTTP1::Connection.new(stream)
	
	def client.read_line
		@stream.read_until(HTTP::Protocol::HTTP1::Connection::CRLF) or raise EOFError
	end
	
	puts "Writing request..."
	client.write_request("www.google.com", "GET", "/search?q=kittens", "HTTP/1.1", [["Accept", "*/*"]])
	client.write_body(nil)
	
	puts "Reading response..."
	response = client.read_response("GET")
	
	puts "Got response: #{response.inspect}"
	
	puts "Closing client..."
	client.close
end

puts "Exiting."

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
http-protocol-0.17.1 examples/http1/request.rb
http-protocol-0.17.0 examples/http1/request.rb
http-protocol-0.16.0 examples/http1/request.rb
http-protocol-0.15.0 examples/http1/request.rb
http-protocol-0.14.0 examples/http1/request.rb
http-protocol-0.13.0 examples/http1/request.rb
http-protocol-0.12.2 examples/http1/request.rb
http-protocol-0.12.1 examples/http1/request.rb
http-protocol-0.12.0 examples/http1/request.rb
http-protocol-0.11.0 examples/http1/request.rb
http-protocol-0.10.1 examples/http1/request.rb