aboutsummaryrefslogtreecommitdiffstats
path: root/examples/client/large.rb
blob: dc4d2a6058b19ac0c9b7dbf5897d800df7a6e44c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen-string-literal: true

# client/large.rb: download 3 large files in parallel
$LOAD_PATH.unshift File.expand_path("../../../lib", __FILE__)
require "plum"

def log(s)
  puts "[#{Time.now.strftime("%Y/%m/%d %H:%M:%S.%L")}] #{s}"
end

Plum::Client.start("http2.golang.org", 443, http2_settings: { max_frame_size: 32768 }) { |rest|
  3.times { |i|
    rest.get("/file/go.src.tar.gz",
             headers: { "accept-encoding" => "identity;q=1" }) { |res|
      log "#{i}: #{res.status}"
      res.on_chunk { |chunk|
        log "#{i}: chunk: #{chunk.size}"
      }
    }
  }
}