aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-11-08 16:16:02 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-11-08 16:16:02 +0900
commit4efc5600fff89080d312889ad76603903b856faa (patch)
treef6934181dd6603442b1b7f4ff6ec42978e47632c /README.md
parentcf95e6c3fefcb21e5c4784497544af0143f45200 (diff)
downloadplum-4efc5600fff89080d312889ad76603903b856faa.tar.gz
readme: update client usage
Diffstat (limited to 'README.md')
-rw-r--r--README.md31
1 files changed, 12 insertions, 19 deletions
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