File: google.rb

package info (click to toggle)
ruby-async-http 0.94.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 916 kB
  • sloc: ruby: 5,224; javascript: 40; makefile: 4
file content (46 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2025, by Samuel Williams.
# Copyright, 2025, by William T. Nelson.

require "async/http/client"
require "async/http/endpoint"
require "async/http/body"

require "protocol/http/accept_encoding"

require "sus/fixtures/async"

describe Async::HTTP::Client do
	include Sus::Fixtures::Async::ReactorContext
	
	let(:endpoint) {Async::HTTP::Endpoint.parse("https://www.google.com")}
	let(:client) {Async::HTTP::Client.new(endpoint)}
	
	it "should specify a hostname" do
		expect(endpoint.hostname).to be == "www.google.com"
		expect(client.authority).to be == "www.google.com"
	end
	
	it "can fetch remote resource" do
		response = client.get("/", {"accept" => "*/*"})
		
		response.finish
		
		expect(response).not.to be(:failure?)
		
		client.close
	end
	
	it "can request remote resource with compression" do
		compressor = Protocol::HTTP::AcceptEncoding.new(client)
		
		response = compressor.get("/", {"accept-encoding" => "gzip"})
		
		expect(response).to be(:success?)
		
		expect(response.body).to be_a Async::HTTP::Body::Inflate
		expect(response.read).to be(:start_with?, "<!doctype html>")
	end
end