From 4efc5600fff89080d312889ad76603903b856faa Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Sun, 8 Nov 2015 16:16:02 +0900 Subject: readme: update client usage --- README.md | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 28132d5..2abc857 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,13 @@ A pure Ruby HTTP/2 implementation. * or latest Ruby 2.3.0-dev * OpenSSL 1.0.2 or newer (HTTP/2 requires ALPN) * Optional: - * [http_parser.rb gem](https://rubygems.org/gems/http_parser.rb) (HTTP/1.1 parser; if you use "http" URI scheme) + * [http_parser.rb gem](https://rubygems.org/gems/http_parser.rb) (HTTP/1.x parser; if you use "http" URI scheme) * [rack gem](https://rubygems.org/gems/rack) if you use Plum as Rack server. ## Usage -### As a HTTP/2 client library +### As a HTTP/2 (HTTP/1.x) client library +If the server does't support HTTP/2, `Plum::Client` tries to use HTTP/1.x instead. + ##### Sequential request ```ruby client = Plum::Client.start("http2.rhe.jp", 443) @@ -25,31 +27,22 @@ client.close ##### Parallel request ```ruby -client = Plum::Client.start("http2.rhe.jp", 443) -res1 = client.get_async("/") -res2 = client.post_async("/post", "data") -client.wait # wait for response(s) -client.close -p res1.status # => 200 -``` -or -```ruby res1 = res2 = nil -Plum::Client.start("http2.rhe.jp", 443) { |client| +Plum::Client.start("rhe.jp", http2_settings: { max_frame_size: 32768 }) { |client| res1 = client.get_async("/") res2 = client.post_async("/post", "data") } # wait for response(s) and close -p res1.status # => 200 +p res1.status # => "200" ``` -##### Download large file +##### Download a large file ```ruby -Plum::Client.start("http2.rhe.jp", 443) { |client| - client.get_async("/large") do |res| - p res.status # => 200 +Plum::Client.start("http2.rhe.jp", hostname: "assets.rhe.jp") { |client| + client.get_async("/large") do |res| # called when received response headers + p res.status # => "200" File.open("/tmp/large.file", "wb") { |file| - res.each_chunk do |chunk| + res.on_chunk do |chunk| file << chunk end } @@ -59,7 +52,7 @@ Plum::Client.start("http2.rhe.jp", 443) { |client| ### As a Rack-compatible server -Most existing Rack-based applications (plum doesn't support Rack hijack API) should work without modification. +Most existing Rack-based applications should work without modification. ```ruby # config.ru -- cgit v1.2.3