{"id":20836550,"url":"https://github.com/kenichi/h2","last_synced_at":"2025-05-08T02:39:53.474Z","repository":{"id":56875633,"uuid":"74863497","full_name":"kenichi/h2","owner":"kenichi","description":"an http/2 client \u0026 server based on http-2 and modern ruby","archived":false,"fork":false,"pushed_at":"2018-08-22T22:50:44.000Z","size":244,"stargazers_count":25,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T03:20:26.385Z","etag":null,"topics":["http2","http2-push","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kenichi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-27T02:54:03.000Z","updated_at":"2023-10-17T06:32:46.000Z","dependencies_parsed_at":"2022-08-20T22:00:47.471Z","dependency_job_id":null,"html_url":"https://github.com/kenichi/h2","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenichi%2Fh2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenichi%2Fh2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenichi%2Fh2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenichi%2Fh2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kenichi","download_url":"https://codeload.github.com/kenichi/h2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252989253,"owners_count":21836656,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http2","http2-push","ruby"],"created_at":"2024-11-18T00:30:37.853Z","updated_at":"2025-05-08T02:39:53.450Z","avatar_url":"https://github.com/kenichi.png","language":"Ruby","readme":"# H2\n\n[![Build Status](https://travis-ci.org/kenichi/h2.svg?branch=master)](https://travis-ci.org/kenichi/h2)\n\nH2 is an HTTP/2 client and server based on the [http-2](https://github.com/igrigorik/http-2) gem.\n\nH2 uses:\n\n* keyword arguments (\u003e=2.0)\n* exception-less socket IO (\u003e=2.3).\n\n## Server Usage\n\nServer API is currently optional, so `h2/server` must be required separately.\nThe server uses [Celluloid::IO](https://github.com/celluloid/celluloid-io), but\nh2's gemspec does not require it, so celluloid-io must be separately added to\n`Gemfile`. It is currently based on `celluloid-io-0.17.3`.\n\n```ruby\nrequire 'h2/server'\n\nserver = H2::Server::HTTP.new host: addr, port: port do |connection|\n  connection.each_stream do |stream|\n    stream.respond status: 200, body: \"hello, world!\\n\"\n    stream.connection.goaway\n  end\nend\n\nstream = H2.get url: \"http://#{addr}:#{port}\", tls: false\nstream.body #=\u003e \"hello, world!\\n\"\n```\n\nSee more server examples:\n\n* [HTTPS Hello World](https://github.com/kenichi/h2/blob/master/examples/server/https_hello_world.rb)\n* [Push Promises](https://github.com/kenichi/h2/blob/master/examples/server/push_promise.rb)\n* [SSE/EventSource](https://github.com/kenichi/h2/blob/master/examples/server/sse.rb)\n\n## Client Usage\n\n```ruby\nrequire 'h2'\n\n#\n# --- one-shot convenience\n#\n\nstream = H2.get url: 'https://example.com'\n\nstream.ok?     #=\u003e true\nstream.headers #=\u003e Hash\nstream.body    #=\u003e String\nstream.closed? #=\u003e true\n\nclient = stream.client #=\u003e H2::Client\n\nclient.closed? #=\u003e true\n\n#\n# --- normal connection\n#\n\nclient = H2::Client.new host: 'example.com', port: 443\n\nstream = client.get path: '/'\n\nstream.ok?     #=\u003e true\nstream.headers #=\u003e Hash, method blocks until stream is closed\nstream.body    #=\u003e String, method blocks until stream is closed\nstream.closed? #=\u003e true\n\nclient.closed? #=\u003e false unless server sent GOAWAY\n\nclient.on :promise do |p| # check/cancel a promise\n  p.on :headers do |h|\n    if h['etag'] == 'some_value'\n      p.cancel!  # already have \n    end\n  end\nend\n\nstream.block! # blocks until this stream and any associated push streams are closed\n\nstream.ok?     #=\u003e true\nstream.headers #=\u003e Hash\nstream.body    #=\u003e String\nstream.closed? #=\u003e true\n\nstream.pushes #=\u003e Set\nstream.pushes.each do |pp|\n  pp.parent == stream #=\u003e true\n  pp.headers          #=\u003e Hash\n  pp.body             #=\u003e String\nend\n\nclient.goaway!\n```\n\n## Client CLI\n\nFor more info on using the CLI `h2` installed with this gem:\n\n`$ h2 --help`\n\n## Using TLS CA Certificates with the Client\n\nIf you're running on macOS and using Homebrew's openssl package, you may need to\nspecify the CA file in the TLS options:\n\n```ruby\nclient = H2::Client.new host: 'example.com', port: 443, tls: { ca_file: '/usr/local/etc/openssl/cert.pem' }\n```\n\nor when using the CLI:\n\n`$ h2 --cafile /usr/local/etc/openssl/cert.pem https://example.com/`\n\n\n## Alternate Concurrency Models\n\nRight now, h2 uses one new thread per connection. This is hardly ideal, so a\ncouple other models are tentatively supported out of the box:\n\n* [celluloid](https://github.com/celluloid/celluloid)\n* [concurrent-ruby](https://github.com/ruby-concurrency/concurrent-ruby)\n\nNeither of these gems are hard dependencies. If you want to use either one, you must\nhave it available to your Ruby VM, most likely via Bundler, *and* require the\nsub-component of h2 that will prepend and extend `H2::Client`. They are also intended\nto be mutually exclusive: you can have both in your VM, but you can only use one at a\ntime with h2's client.\n\n#### Celluloid Pool\n\nTo use a celluloid actor pool for reading from `H2::Client` connections:\n\n```ruby\nrequire 'h2/client/celluloid'\n```\n\nThis will lazily fire up a celluloid pool, with defaults defined by Celluloid.\n\nNOTE: if you've added celluloid-io and required the 'h2/server' API, Celluloid \nwill be loaded in your Ruby VM already; however, you must still require this to\nhave the client use Celluloid actor pools.\n\n#### Concurrent-Ruby ThreadPoolExecutor\n\nTo use a concurrent-ruby thread pool executor for reading from `H2::Client` connections:\n\n```ruby\nrequire 'h2/client/concurrent'\n```\n\nThis will lazily fire up a `Concurrent::ThreadPoolExecutor` with the following settings:\n\n```ruby\nprocs = ::Concurrent.processor_count\n\nmin_threads: 0,\nmax_threads: procs,\nmax_queue:   procs * 5\n```\n\n## TODO\n\n* [x] HTTPS / TLS\n* [x] push promise cancellation\n* [x] alternate concurrency models\n* [ ] fix up CLI to be more curlish\n* [ ] update server API\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/kenichi/h2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenichi%2Fh2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkenichi%2Fh2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenichi%2Fh2/lists"}