aboutsummaryrefslogtreecommitdiffstats
path: root/examples/client/synchronous.rb
blob: 6701e1e5a2d91e7f4dbd95d40f7404c3bd6b793a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen-string-literal: true
# client/synchronous.rb: download 3 files in sequence
$LOAD_PATH.unshift File.expand_path("../../../lib", __FILE__)
require "plum"
require "zlib"

client = Plum::Client.start("http2.golang.org", 443)

reqinfo = client.get("/reqinfo").join
puts "/reqinfo: #{reqinfo.status}"

test = "test"
crc32 = client.put("/crc32", test).join
puts "/crc32{#{test}}: #{crc32.body}"
puts "Zlib.crc32: #{Zlib.crc32(test).to_s(16)}"

client.get("/clockstream")
  .on_headers { |res|
  puts "status: #{res.status}, headers: #{res.headers}"
  }.on_chunk { |chunk|
    puts chunk
  }.on_finish {
    puts "finish!"
  }.join