aboutsummaryrefslogtreecommitdiffstats
path: root/examples/client/synchronous.rb
diff options
context:
space:
mode:
Diffstat (limited to 'examples/client/synchronous.rb')
-rw-r--r--examples/client/synchronous.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/client/synchronous.rb b/examples/client/synchronous.rb
new file mode 100644
index 0000000..6701e1e
--- /dev/null
+++ b/examples/client/synchronous.rb
@@ -0,0 +1,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