biryani 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +30 -0
  3. data/.gitignore +17 -0
  4. data/.rubocop.yml +36 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +9 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +48 -0
  9. data/Rakefile +8 -0
  10. data/biryani.gemspec +21 -0
  11. data/example/echo.rb +27 -0
  12. data/example/hello_world.rb +22 -0
  13. data/lib/biryani/connection.rb +464 -0
  14. data/lib/biryani/connection_error.rb +17 -0
  15. data/lib/biryani/data_buffer.rb +42 -0
  16. data/lib/biryani/frame/continuation.rb +48 -0
  17. data/lib/biryani/frame/data.rb +70 -0
  18. data/lib/biryani/frame/goaway.rb +44 -0
  19. data/lib/biryani/frame/headers.rb +110 -0
  20. data/lib/biryani/frame/ping.rb +49 -0
  21. data/lib/biryani/frame/priority.rb +44 -0
  22. data/lib/biryani/frame/push_promise.rb +75 -0
  23. data/lib/biryani/frame/rst_stream.rb +40 -0
  24. data/lib/biryani/frame/settings.rb +66 -0
  25. data/lib/biryani/frame/unknown.rb +42 -0
  26. data/lib/biryani/frame/window_update.rb +43 -0
  27. data/lib/biryani/frame.rb +146 -0
  28. data/lib/biryani/hpack/decoder.rb +22 -0
  29. data/lib/biryani/hpack/dynamic_table.rb +65 -0
  30. data/lib/biryani/hpack/encoder.rb +22 -0
  31. data/lib/biryani/hpack/error.rb +12 -0
  32. data/lib/biryani/hpack/field.rb +357 -0
  33. data/lib/biryani/hpack/fields.rb +28 -0
  34. data/lib/biryani/hpack/huffman.rb +309 -0
  35. data/lib/biryani/hpack/integer.rb +66 -0
  36. data/lib/biryani/hpack/option.rb +24 -0
  37. data/lib/biryani/hpack/string.rb +40 -0
  38. data/lib/biryani/hpack.rb +84 -0
  39. data/lib/biryani/http_request.rb +83 -0
  40. data/lib/biryani/http_response.rb +61 -0
  41. data/lib/biryani/server.rb +19 -0
  42. data/lib/biryani/state.rb +224 -0
  43. data/lib/biryani/stream.rb +19 -0
  44. data/lib/biryani/stream_error.rb +17 -0
  45. data/lib/biryani/streams_context.rb +89 -0
  46. data/lib/biryani/version.rb +3 -0
  47. data/lib/biryani/window.rb +29 -0
  48. data/lib/biryani.rb +17 -0
  49. data/spec/connection/close_all_streams_spec.rb +17 -0
  50. data/spec/connection/handle_connection_window_update_spec.rb +16 -0
  51. data/spec/connection/handle_ping_spec.rb +21 -0
  52. data/spec/connection/handle_rst_stream_spec.rb +21 -0
  53. data/spec/connection/handle_settings_spec.rb +31 -0
  54. data/spec/connection/handle_stream_window_update_spec.rb +20 -0
  55. data/spec/connection/read_http2_magic_spec.rb +26 -0
  56. data/spec/connection/remove_closed_streams_spec.rb +51 -0
  57. data/spec/connection/send_spec.rb +114 -0
  58. data/spec/connection/transition_state_send_spec.rb +39 -0
  59. data/spec/connection/unwrap_spec.rb +28 -0
  60. data/spec/data_buffer_spec.rb +135 -0
  61. data/spec/frame/continuation_spec.rb +39 -0
  62. data/spec/frame/data_spec.rb +25 -0
  63. data/spec/frame/goaway_spec.rb +23 -0
  64. data/spec/frame/headers_spec.rb +52 -0
  65. data/spec/frame/ping_spec.rb +22 -0
  66. data/spec/frame/priority_spec.rb +22 -0
  67. data/spec/frame/push_promise_spec.rb +24 -0
  68. data/spec/frame/read_spec.rb +30 -0
  69. data/spec/frame/rst_stream_spec.rb +21 -0
  70. data/spec/frame/settings_spec.rb +23 -0
  71. data/spec/frame/window_update_spec.rb +21 -0
  72. data/spec/hpack/decoder_spec.rb +170 -0
  73. data/spec/hpack/encoder_spec.rb +48 -0
  74. data/spec/hpack/field_spec.rb +42 -0
  75. data/spec/hpack/fields_spec.rb +17 -0
  76. data/spec/hpack/huffman_spec.rb +20 -0
  77. data/spec/hpack/integer_spec.rb +27 -0
  78. data/spec/hpack/string_spec.rb +19 -0
  79. data/spec/http_request_builder_spec.rb +45 -0
  80. data/spec/spec_helper.rb +9 -0
  81. metadata +165 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 00cbfab00ec034ee2b79096e4192e363426dbcd0c70e59578b9ead09b2a05865
4
+ data.tar.gz: d0f78a6b2541464bbf9e0295b13ce576defd8f7a057c200c0c9118a8650ca882
5
+ SHA512:
6
+ metadata.gz: 11759d99704bbd2d7fc525c30e30022eebd42396c6db918802b8424832fa4abfc9a47390e1abbb0bcbd9063e2acb74f9fb95b685fac9dd9a389a931e71ef433d
7
+ data.tar.gz: 4c55e5e2a86a5b65e0e92d34b1e216fc699b18fc5d84486d07c0103a3b813173039bd7ec123b5b781b46c396d87d6d87ae263a1215150df3633ca012e2070238
@@ -0,0 +1,30 @@
1
+ name: lint & test
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - '*'
10
+
11
+ jobs:
12
+ ci:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby-version: ['4.0']
17
+ steps:
18
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@ae195bbe749a7cef685ac729197124a48305c1cb # v1.276.0
21
+ with:
22
+ ruby-version: ${{ matrix.ruby-version }}
23
+ - name: Install dependencies
24
+ run: |
25
+ gem --version
26
+ gem install bundler
27
+ bundle --version
28
+ bundle install
29
+ - name: Run rubocop & rspec
30
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .config
4
+ .rvmrc
5
+ /.bundle/
6
+ /vendor/
7
+ /lib/bundler/man/
8
+ /pkg/
9
+ /.yardoc/
10
+ /_yardoc/
11
+ /doc/
12
+ /rdoc/
13
+ /coverage/
14
+ /spec/reports/
15
+ /tmp/
16
+ .DS_Store
17
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,36 @@
1
+ AllCops:
2
+ TargetRubyVersion: 4.0
3
+
4
+ Layout/LineLength:
5
+ Max: 200
6
+
7
+ Metrics/AbcSize:
8
+ Max: 30
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - 'spec/**/*'
13
+
14
+ Metrics/ClassLength:
15
+ Max: 200
16
+
17
+ Metrics/MethodLength:
18
+ Max: 30
19
+
20
+ Naming/MethodParameterName:
21
+ MinNameLength: 1
22
+
23
+ Naming/FileName:
24
+ Enabled: false
25
+
26
+ Naming/ClassAndModuleCamelCase:
27
+ Enabled: false
28
+
29
+ Semicolon:
30
+ AllowAsExpressionSeparator: true
31
+
32
+ Style/Documentation:
33
+ Enabled: false
34
+
35
+ Style/FrozenStringLiteralComment:
36
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 4.0.0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'rake', '13.3.1'
5
+ gem 'rspec'
6
+ gem 'rubocop', '1.82.1'
7
+ end
8
+
9
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Tomoya Kuwayama
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # biryani
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/biryani.svg)](https://badge.fury.io/rb/biryani)
4
+ [![Actions Status](https://github.com/thekuwayama/biryani/actions/workflows/ci.yml/badge.svg)](https://github.com/thekuwayama/biryani/actions/workflows/ci.yml)
5
+ [![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.txt)
6
+
7
+ `biryani` is an HTTP/2 server implemented using Ruby Ractor.
8
+
9
+ - https://datatracker.ietf.org/doc/rfc9113/
10
+ - https://datatracker.ietf.org/doc/rfc7541/
11
+
12
+
13
+ ## Installation
14
+
15
+ The gem is available at [rubygems.org](https://rubygems.org/gems/biryani). You can install it the following:
16
+
17
+ ```sh-session
18
+ $ gem install biryani
19
+ ```
20
+
21
+
22
+ ## Usage
23
+
24
+ This implementation intentionally provides a minimal API and delegates application-level responsibilities to your code.
25
+ Roughly, it works as follows:
26
+
27
+ ```ruby
28
+ require 'socket'
29
+ require 'biryani'
30
+
31
+ port = ARGV[0] || 8888
32
+ socket = TCPServer.new(port)
33
+
34
+ server = Biryani::Server.new(
35
+ # @params _req [Biryani::HTTPRequest]
36
+ # @params res [Biryani::HTTPResponse]
37
+ Ractor.shareable_proc do |_req, res|
38
+ res.status = 200
39
+ res.content = 'Hello, world!'
40
+ end
41
+ )
42
+ server.run(socket)
43
+ ```
44
+
45
+
46
+ ## License
47
+
48
+ `biryani` is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RuboCop::RakeTask.new
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: %i[rubocop spec]
data/biryani.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'biryani/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'biryani'
7
+ spec.version = Biryani::VERSION
8
+ spec.authors = ['thekuwayama']
9
+ spec.email = ['thekuwayama@gmail.com']
10
+ spec.summary = 'An HTTP/2 server implemented using Ruby Ractor'
11
+ spec.description = spec.summary
12
+ spec.homepage = 'https://github.com/thekuwayama/biryani'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = '>=4.0'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler'
21
+ end
data/example/echo.rb ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << "#{__dir__}/../lib"
4
+
5
+ require 'socket'
6
+ require 'biryani'
7
+
8
+ port = ARGV[0] || 8888
9
+ socket = TCPServer.new(port)
10
+
11
+ server = Biryani::Server.new(
12
+ # @params req [Biryani::HTTPRequest]
13
+ # @params res [Biryani::HTTPResponse]
14
+ Ractor.shareable_proc do |req, res|
15
+ res.status = 200
16
+
17
+ res.content = if req.method.upcase == 'POST'
18
+ req.content
19
+ else
20
+ ''
21
+ end
22
+ end
23
+ )
24
+ server.run(socket)
25
+
26
+ # $ bundle exec ruby example/echo.rb
27
+ # $ curl -v --http2-prior-knowledge http://localhost:8888 -X POST -d hi
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << "#{__dir__}/../lib"
4
+
5
+ require 'socket'
6
+ require 'biryani'
7
+
8
+ port = ARGV[0] || 8888
9
+ socket = TCPServer.new(port)
10
+
11
+ server = Biryani::Server.new(
12
+ # @params _req [Biryani::HTTPRequest]
13
+ # @params res [Biryani::HTTPResponse]
14
+ Ractor.shareable_proc do |_req, res|
15
+ res.status = 200
16
+ res.content = 'Hello, world!'
17
+ end
18
+ )
19
+ server.run(socket)
20
+
21
+ # $ bundle exec ruby example/hello_world.rb
22
+ # $ curl -v --http2-prior-knowledge http://localhost:8888