Skip to content

Commit

Permalink
Modernize gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jul 28, 2024
1 parent 77034ea commit 2ce3a57
Show file tree
Hide file tree
Showing 34 changed files with 308 additions and 224 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/documentation-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Documentation Coverage

on: [push, pull_request]

permissions:
contents: read

env:
CONSOLE_OUTPUT: XTerm
COVERAGE: PartialSummary

jobs:
validate:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true

- name: Validate coverage
timeout-minutes: 5
run: bundle exec bake decode:index:coverage lib
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: bundle exec bake utopia:project:static --force no

- name: Upload documentation artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
with:
path: docs

Expand All @@ -55,4 +55,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v3
uses: actions/deploy-pages@v4
24 changes: 24 additions & 0 deletions .github/workflows/rubocop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: RuboCop

on: [push, pull_request]

permissions:
contents: read

env:
CONSOLE_OUTPUT: XTerm

jobs:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ruby
bundler-cache: true

- name: Run RuboCop
timeout-minutes: 10
run: bundle exec rubocop
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Coverage
name: Test Coverage

on: [push, pull_request]

Expand Down Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Run tests
timeout-minutes: 5
run: bundle exec bake test

- uses: actions/upload-artifact@v3
with:
name: coverage-${{matrix.os}}-${{matrix.ruby}}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test-external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
- macos

ruby:
- "3.0"
- "3.1"
- "3.2"
- "3.3"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
- macos

ruby:
- "3.0"
- "3.1"
- "3.2"
- "3.3"
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "spec/protocol/hpack/fixtures"]
path = spec/protocol/hpack/fixtures
[submodule "test/protocol/hpack/fixtures"]
path = test/protocol/hpack/fixtures
url = https://github.com/http2jp/hpack-test-case.git
3 changes: 0 additions & 3 deletions .rspec

This file was deleted.

46 changes: 46 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
AllCops:
DisabledByDefault: true

Layout/IndentationStyle:
Enabled: true
EnforcedStyle: tabs

Layout/InitialIndentation:
Enabled: true

Layout/IndentationWidth:
Enabled: true
Width: 1

Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: normal

Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: start_of_line

Layout/BeginEndAlignment:
Enabled: true
EnforcedStyleAlignWith: start_of_line

Layout/ElseAlignment:
Enabled: true

Layout/DefEndAlignment:
Enabled: true

Layout/CaseIndentation:
Enabled: true

Layout/CommentIndentation:
Enabled: true

Layout/EmptyLinesAroundClassBody:
Enabled: true

Layout/EmptyLinesAroundModuleBody:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: true
7 changes: 7 additions & 0 deletions config/sus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require 'covered/sus'
include Covered::Sus
20 changes: 11 additions & 9 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
# Specify your gem's dependencies in protocol-hpack.gemspec
gemspec

gem "rake", "~> 10.0"
group :maintenance, optional: true do
gem "bake-gem"
gem "bake-modernize"

gem "rake", "~> 10.0"

gem "utopia-project"
end

group :test do
gem "rspec", "~> 3.0"
gem "sus"
gem "covered"
gem "decode"
gem "rubocop"

gem "bake-test"
gem "bake-test-external"
end

group :maintenance, optional: true do
gem "bake-gem"
gem "bake-modernize"

gem "utopia-project"
end
1 change: 1 addition & 0 deletions lib/protocol/hpack/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Released under the MIT License.
# Copyright, 2018-2024, by Samuel Williams.
# Copyright, 2024, by Maruth Goyal.

require_relative 'huffman'

Expand Down
1 change: 1 addition & 0 deletions lib/protocol/hpack/decompressor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Released under the MIT License.
# Copyright, 2018-2024, by Samuel Williams.
# Copyright, 2024, by Maruth Goyal.

require_relative 'context'
require_relative 'huffman'
Expand Down
2 changes: 2 additions & 0 deletions license.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Copyright, 2020, by Olle Jonsson.
Copyright, 2020, by Justin Mazzocchi.
Copyright, 2022, by Daniel Morrison.
Copyright, 2022, by Felix Yan.
Copyright, 2024, by Maruth Goyal.
Copyright, 2024, by Nathan Froyd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 3 additions & 2 deletions protocol-hpack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
spec.version = Protocol::HPACK::VERSION

spec.summary = "A compresssor and decompressor for HTTP/2's HPACK format."
spec.authors = ["Samuel Williams", "Ilya Grigorik", "Tamir Duberstein", "Kaoru Maeda", "Tiago Cardoso", "Byron Formwalt", "Cyril Roelandt", "Daniel Morrison", "Felix Yan", "George Ulmer", "Jingyi Chen", "Justin Mazzocchi", "Kenichi Nakamura", "Kien Nguyen Trung", "Olle Jonsson"]
spec.authors = ["Samuel Williams", "Ilya Grigorik", "Tamir Duberstein", "Kaoru Maeda", "Tiago Cardoso", "Byron Formwalt", "Cyril Roelandt", "Daniel Morrison", "Felix Yan", "George Ulmer", "Jingyi Chen", "Justin Mazzocchi", "Kenichi Nakamura", "Kien Nguyen Trung", "Maruth Goyal", "Nathan Froyd", "Olle Jonsson"]
spec.license = "MIT"

spec.cert_chain = ['release.cert']
Expand All @@ -17,9 +17,10 @@ Gem::Specification.new do |spec|

spec.metadata = {
"documentation_uri" => "https://socketry.github.io/protocol-hpack/",
"source_code_uri" => "https://github.com/socketry/http-hpack.git",
}

spec.files = Dir.glob(['{lib,tasks}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__)

spec.required_ruby_version = ">= 3.0"
spec.required_ruby_version = ">= 3.1"
end
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ We welcome contributions to this project.

### Developer Certificate of Origin

This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.

### Contributor Covenant
### Community Guidelines

This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.

## See Also

- [protocol-http2](https://github.com/socketry/protocol-http2) - Provides an HTTP/2 client and server implementation.
- [async-http](https://github.com/socketry/async-http) - Provides a complete HTTP client and server implementation on top of Async.
- [protocol-http2](https://github.com/socketry/protocol-http2) - Provides an HTTP/2 client and server implementation.
- [async-http](https://github.com/socketry/async-http) - Provides a complete HTTP client and server implementation on top of Async.
18 changes: 0 additions & 18 deletions spec/spec_helper.rb

This file was deleted.

1 change: 1 addition & 0 deletions tasks/huffman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Copyright, 2015, by Ilya Grigorik.
# Copyright, 2016, by George Ulmer.
# Copyright, 2018-2024, by Samuel Williams.
# Copyright, 2024, by Nathan Froyd.

require_relative '../lib/protocol/hpack/huffman'

Expand Down
4 changes: 2 additions & 2 deletions spec/protocol/hpack_spec.rb → test/protocol/hpack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

require 'protocol/hpack'

RSpec.describe Protocol::HPACK do
describe Protocol::HPACK do
it "has a version number" do
expect(Protocol::HPACK::VERSION).not_to be nil
expect(Protocol::HPACK::VERSION).to be =~ /\d+\.\d+\.\d+/
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,46 @@

require 'json'

RSpec.describe Protocol::HPACK::Compressor do
describe '#write_integer' do
describe Protocol::HPACK::Compressor do
with '#write_integer' do
let(:buffer) {String.new.b}
subject {described_class.new(buffer)}
let(:compressor) {subject.new(buffer)}

context '0-bit prefix' do
with '0-bit prefix' do
it "can encode the value 10" do
subject.write_integer(10, 0)
compressor.write_integer(10, 0)
expect(buffer).to be == [10].pack('C')
end

it "can encode the value 1337" do
subject.write_integer(1337, 0)
compressor.write_integer(1337, 0)
expect(buffer).to be == [128 + 57, 10].pack('C*')
end
end

context '5-bit prefix' do
with '5-bit prefix' do
it "can encode the value 10" do
subject.write_integer(10, 5)
compressor.write_integer(10, 5)
expect(buffer).to be == [10].pack('C')
end

it "can encode the value 1337" do
subject.write_integer(1337, 5)
compressor.write_integer(1337, 5)
expect(buffer).to be == [31, 128 + 26, 10].pack('C*')
end
end
end

describe '#write_string' do
with '#write_string' do
[
['with huffman', :always, 0x80],
['without huffman', :never, 0],
].each do |description, huffman, msb|
context description do
with description do
let(:context) {Protocol::HPACK::Context.new(huffman: huffman)}
let(:buffer) {String.new.b}

subject {Protocol::HPACK::Compressor.new(buffer, context)}
let(:compressor) {Protocol::HPACK::Compressor.new(buffer, context)}
let(:decompressor) {Protocol::HPACK::Decompressor.new(buffer, context)}

[
Expand All @@ -63,35 +63,35 @@
['long utf-8 strings', 'éáűőúöüó€' * 100],
].each do |datatype, plain|
it "should handle #{datatype} #{description}" do
subject.write_string(plain)
expect(buffer.getbyte(0) & 0x80).to eq msb
compressor.write_string(plain)
expect(buffer.getbyte(0) & 0x80).to be == msb

expect(decompressor.read_string).to eq plain
expect(decompressor.read_string).to be == plain
end
end
end
end

context 'choosing shorter representation' do
with 'choosing shorter representation' do
let(:context) {Protocol::HPACK::Context.new(huffman: :shorter)}
let(:buffer) {String.new.b}

subject {Protocol::HPACK::Compressor.new(buffer, context)}
let(:compressor) {Protocol::HPACK::Compressor.new(buffer, context)}

[
['日本語', :plain],
['200', :huffman],
['xq', :plain], # prefer plain if equal size
].each do |string, choice|
it "should return #{choice} representation" do
subject.write_string(string)
expect(buffer.getbyte(0) & 0x80).to eq(choice == :plain ? 0 : 0x80)
compressor.write_string(string)
expect(buffer.getbyte(0) & 0x80).to be == (choice == :plain ? 0 : 0x80)
end
end
end
end

describe '#encode' do
with '#encode' do
let(:path) {File.expand_path("sequence1.json", __dir__)}
let(:sequence) {JSON.parse(File.read(path))}

Expand Down
Loading

0 comments on commit 2ce3a57

Please sign in to comment.