Skip to content

Commit

Permalink
Modernize gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 17, 2024
1 parent bc1bfa0 commit 6792836
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:

- uses: actions/upload-artifact@v4
with:
include-hidden-files: true
if-no-files-found: error
name: coverage-${{matrix.os}}-${{matrix.ruby}}
path: .covered.db

Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ Layout/EmptyLinesAroundModuleBody:

Style/FrozenStringLiteralComment:
Enabled: true

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
4 changes: 2 additions & 2 deletions config/sus.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

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

require 'covered/sus'
require "covered/sus"
include Covered::Sus
6 changes: 3 additions & 3 deletions examples/early-hints/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# frozen_string_literal: true

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

$LOAD_PATH.unshift File.expand_path("../../lib", __dir__)

require 'async'
require 'async/http/endpoint'
require "async"
require "async/http/endpoint"

RESPONSE = <<~HTTP.split(/\r?\n/).join("\r\n")
HTTP/1.1 103 Early Hints
Expand Down
6 changes: 3 additions & 3 deletions examples/http1/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)

require 'async'
require 'async/http/endpoint'
require 'protocol/http1/connection'
require "async"
require "async/http/endpoint"
require "protocol/http1/connection"

Async do
endpoint = Async::HTTP::Endpoint.parse("http://localhost:8080")
Expand Down
6 changes: 3 additions & 3 deletions examples/http1/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)

require 'socket'
require 'protocol/http1/connection'
require 'protocol/http/body/buffered'
require "socket"
require "protocol/http1/connection"
require "protocol/http/body/buffered"

# Test with: curl http://localhost:8080/

Expand Down
6 changes: 3 additions & 3 deletions fixtures/connection_context.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

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

require 'protocol/http1/connection'
require "protocol/http1/connection"

require 'socket'
require "socket"

ConnectionContext = Sus::Shared("a connection") do
let(:sockets) {Socket.pair(Socket::PF_UNIX, Socket::SOCK_STREAM)}
Expand Down
10 changes: 5 additions & 5 deletions fuzz/request/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# frozen_string_literal: true

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

require 'socket'
require_relative '../../lib/protocol/http1'
require "socket"
require_relative "../../lib/protocol/http1"

def test
# input, output = Socket.pair(Socket::PF_UNIX, Socket::SOCK_STREAM)
Expand All @@ -25,8 +25,8 @@ def test
end

if ENV["_"] =~ /afl/
require 'kisaten'
Kisaten.crash_at [], [], Signal.list['USR1']
require "kisaten"
Kisaten.crash_at [], [], Signal.list["USR1"]

while Kisaten.loop 10000
test
Expand Down
6 changes: 3 additions & 3 deletions lib/protocol/http1.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

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

require_relative 'http1/version'
require_relative 'http1/connection'
require_relative "http1/version"
require_relative "http1/connection"
2 changes: 1 addition & 1 deletion lib/protocol/http1/body/chunked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright, 2019-2024, by Samuel Williams.
# Copyright, 2023, by Thomas Morgan.

require 'protocol/http/body/readable'
require "protocol/http/body/readable"

module Protocol
module HTTP1
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/http1/body/fixed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require 'protocol/http/body/readable'
require "protocol/http/body/readable"

module Protocol
module HTTP1
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/http1/body/remainder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require 'protocol/http/body/readable'
require "protocol/http/body/readable"

module Protocol
module HTTP1
Expand Down
32 changes: 16 additions & 16 deletions lib/protocol/http1/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@
# Copyright, 2023-2024, by Thomas Morgan.
# Copyright, 2024, by Anton Zhuravsky.

require 'protocol/http/headers'
require "protocol/http/headers"

require_relative 'reason'
require_relative 'error'
require_relative "reason"
require_relative "error"

require_relative 'body/chunked'
require_relative 'body/fixed'
require_relative 'body/remainder'
require 'protocol/http/body/head'
require_relative "body/chunked"
require_relative "body/fixed"
require_relative "body/remainder"
require "protocol/http/body/head"

require 'protocol/http/methods'
require "protocol/http/methods"

module Protocol
module HTTP1
CONTENT_LENGTH = 'content-length'
CONTENT_LENGTH = "content-length"

TRANSFER_ENCODING = 'transfer-encoding'
CHUNKED = 'chunked'
TRANSFER_ENCODING = "transfer-encoding"
CHUNKED = "chunked"

CONNECTION = 'connection'
CLOSE = 'close'
KEEP_ALIVE = 'keep-alive'
CONNECTION = "connection"
CLOSE = "close"
KEEP_ALIVE = "keep-alive"

HOST = 'host'
UPGRADE = 'upgrade'
HOST = "host"
UPGRADE = "upgrade"

# HTTP/1.x request line parser:
TOKEN = /[!#$%&'*+\-\.\^_`|~0-9a-zA-Z]+/.freeze
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/http1/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require 'protocol/http/error'
require "protocol/http/error"

module Protocol
module HTTP1
Expand Down
4 changes: 2 additions & 2 deletions lib/protocol/http1/reason.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

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

require 'protocol/http/error'
require "protocol/http/error"

module Protocol
module HTTP1
Expand Down
6 changes: 3 additions & 3 deletions protocol-http1.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
spec.authors = ["Samuel Williams", "Thomas Morgan", "Anton Zhuravsky", "Brian Morearty", "Bruno Sutic", "Olle Jonsson"]
spec.license = "MIT"

spec.cert_chain = ['release.cert']
spec.signing_key = File.expand_path('~/.gem/release.pem')
spec.cert_chain = ["release.cert"]
spec.signing_key = File.expand_path("~/.gem/release.pem")

spec.homepage = "https://github.com/socketry/protocol-http1"

Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/socketry/protocol-http1.git",
}

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

spec.required_ruby_version = ">= 3.1"

Expand Down
4 changes: 2 additions & 2 deletions test/protocol/http1.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

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

require 'protocol/http1/version'
require "protocol/http1/version"

describe Protocol::HTTP1 do
it "has a version number" do
Expand Down
14 changes: 7 additions & 7 deletions test/protocol/http1/body/chunked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require 'protocol/http1/body/chunked'
require 'connection_context'
require "protocol/http1/body/chunked"
require "connection_context"

describe Protocol::HTTP1::Body::Chunked do
let(:content) {"Hello World"}
Expand Down Expand Up @@ -60,24 +60,24 @@
let(:postfix) {"ETag: abcd\r\n"}

it "can read trailing etag" do
headers.add('trailer', 'etag')
headers.add("trailer", "etag")

expect(body.read).to be == "Hello World"
expect(headers['etag']).to be_nil
expect(headers["etag"]).to be_nil

expect(body.read).to be == nil
expect(headers['etag']).to be == 'abcd'
expect(headers["etag"]).to be == "abcd"
end
end

with "bad trailers" do
let(:postfix) {":ETag abcd\r\n"}

it "raises error" do
headers.add('trailer', 'etag')
headers.add("trailer", "etag")

expect(body.read).to be == "Hello World"
expect(headers['etag']).to be_nil
expect(headers["etag"]).to be_nil

expect{body.read}.to raise_exception(Protocol::HTTP1::BadHeader)
end
Expand Down
2 changes: 1 addition & 1 deletion test/protocol/http1/body/fixed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require 'protocol/http1/body/fixed'
require "protocol/http1/body/fixed"

describe Protocol::HTTP1::Body::Fixed do
let(:content) {"Hello World"}
Expand Down
2 changes: 1 addition & 1 deletion test/protocol/http1/body/remainder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require 'protocol/http1/body/remainder'
require "protocol/http1/body/remainder"

describe Protocol::HTTP1::Body::Remainder do
let(:content) {"Hello World"}
Expand Down
Loading

0 comments on commit 6792836

Please sign in to comment.