Skip to content

Commit 94703cf

Browse files
committed
Modernize code.
1 parent 5a500bc commit 94703cf

File tree

12 files changed

+100
-59
lines changed

12 files changed

+100
-59
lines changed

.github/copilot-instructions.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# GitHub Copilot Instructions
2+
3+
## Use Agent Context
4+
5+
When working on this project, consult the `agents.md` file for project-specific guidelines, architecture decisions, and development patterns. This file contains curated information that will help you make better decisions aligned with the project's goals and standards.
6+
7+
If the file does not exist, you will need to install it, by running the following command:
8+
9+
```bash
10+
$ bundle install
11+
$ bundle exec bake agent:context:install
12+
```
13+
14+
This command will set up the necessary context files that help you understand the project structure, dependencies, and conventions.
15+
16+
## Ignoring Files
17+
18+
The `.gitignore` file is split into two sections, separated by a blank line. The first section is automatically generated, while the second section is user controlled.
19+
20+
While working on pull requests, you should not add unrelated changes to the `.gitignore` file as part of the pull request.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/.bundle
1+
/agents.md
22
/.context
3+
/.bundle
34
/pkg
45
/gems.locked
56
/.covered.db

.rubocop.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
plugins:
2+
- rubocop-md
23
- rubocop-socketry
34

45
AllCops:
56
DisabledByDefault: true
67

8+
# Socketry specific rules:
9+
710
Layout/ConsistentBlankLineIndentation:
811
Enabled: true
912

13+
Layout/BlockDelimiterSpacing:
14+
Enabled: true
15+
16+
Style/GlobalExceptionVariables:
17+
Enabled: true
18+
19+
# General Layout rules:
20+
1021
Layout/IndentationStyle:
1122
Enabled: true
1223
EnforcedStyle: tabs
@@ -33,6 +44,9 @@ Layout/BeginEndAlignment:
3344
Enabled: true
3445
EnforcedStyleAlignWith: start_of_line
3546

47+
Layout/RescueEnsureAlignment:
48+
Enabled: true
49+
3650
Layout/ElseAlignment:
3751
Enabled: true
3852

@@ -41,10 +55,15 @@ Layout/DefEndAlignment:
4155

4256
Layout/CaseIndentation:
4357
Enabled: true
58+
EnforcedStyle: end
4459

4560
Layout/CommentIndentation:
4661
Enabled: true
4762

63+
Layout/FirstHashElementIndentation:
64+
Enabled: true
65+
EnforcedStyle: consistent
66+
4867
Layout/EmptyLinesAroundClassBody:
4968
Enabled: true
5069

examples/server/server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
# Released under the MIT License.
5-
# Copyright, 2022-2024, by Samuel Williams.
5+
# Copyright, 2022-2025, by Samuel Williams.
66

77
require "async"
88
require "async/http/server"

gems.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
gem "decode"
2222

2323
gem "rubocop"
24+
gem "rubocop-md"
2425
gem "rubocop-socketry"
2526

2627
gem "sus-fixtures-async"

readme.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@ Please see the [project documentation](https://socketry.github.io/protocol-rack/
1818
Given a rack application, you can adapt it for use on `async-http`:
1919

2020
``` ruby
21-
require 'async'
22-
require 'async/http/server'
23-
require 'async/http/client'
24-
require 'async/http/endpoint'
25-
require 'protocol/rack/adapter'
21+
require "async"
22+
require "async/http/server"
23+
require "async/http/client"
24+
require "async/http/endpoint"
25+
require "protocol/rack/adapter"
2626

2727
app = proc{|env| [200, {}, ["Hello World"]]}
2828
middleware = Protocol::Rack::Adapter.new(app)
2929

3030
Async do
31-
endpoint = Async::HTTP::Endpoint.parse("http://localhost:9292")
32-
33-
server_task = Async(transient: true) do
34-
server = Async::HTTP::Server.new(middleware, endpoint)
35-
server.run
36-
end
37-
38-
client = Async::HTTP::Client.new(endpoint)
39-
puts client.get("/").read
40-
# "Hello World"
31+
endpoint = Async::HTTP::Endpoint.parse("http://localhost:9292")
32+
33+
server_task = Async(transient: true) do
34+
server = Async::HTTP::Server.new(middleware, endpoint)
35+
server.run
36+
end
37+
38+
client = Async::HTTP::Client.new(endpoint)
39+
puts client.get("/").read
40+
# "Hello World"
4141
end
4242
```
4343

@@ -46,21 +46,21 @@ end
4646
While not tested, in theory any Rack compatible server can host `Protocol::HTTP` compatible middlewares.
4747

4848
``` ruby
49-
require 'protocol/http/middleware'
50-
require 'protocol/rack'
49+
require "protocol/http/middleware"
50+
require "protocol/rack"
5151

5252
# Your native application:
5353
middleware = Protocol::HTTP::Middleware::HelloWorld
5454

55-
run proc{|env|
56-
# Convert the rack request to a compatible rich request object:
57-
request = Protocol::Rack::Request[env]
58-
59-
# Call your application
60-
response = middleware.call(request)
61-
62-
Protocol::Rack::Adapter.make_response(env, response)
63-
}
55+
run do |env|
56+
# Convert the rack request to a compatible rich request object:
57+
request = Protocol::Rack::Request[env]
58+
59+
# Call your application
60+
response = middleware.call(request)
61+
62+
Protocol::Rack::Adapter.make_response(env, response)
63+
end
6464
```
6565

6666
## Releases

test/protocol/rack/adapter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
let(:response) {client.get("/")}
179179

180180
with "nil response" do
181-
let(:app) {->(env) {nil}}
181+
let(:app) {->(env){nil}}
182182

183183
it "raises an error" do
184184
expect(response.status).to be == 500
@@ -187,7 +187,7 @@
187187
end
188188

189189
with "nil headers" do
190-
let(:app) {->(env) {[200, nil, []]}}
190+
let(:app) {->(env){[200, nil, []]}}
191191

192192
it "raises an error" do
193193
expect(response.status).to be == 500

test/protocol/rack/adapter/generic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125

126126
with "response callbacks" do
127127
let(:callback_called) {false}
128-
let(:callback) {->(env, status, headers, exception) {@callback_called = true}}
128+
let(:callback) {->(env, status, headers, exception){@callback_called = true}}
129129
let(:app) do
130130
proc do |env|
131131
env[Protocol::Rack::RACK_RESPONSE_FINISHED] = [callback]

test/protocol/rack/adapter/rack2.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@
1414
include Sus::Fixtures::Console::CapturedLogger
1515

1616
with "#call" do
17-
let(:app) {->(env) {[200, {}, []]}}
17+
let(:app) {->(env){[200, {}, []]}}
1818
let(:adapter) {subject.new(app)}
1919

2020
let(:body) {Protocol::HTTP::Body::Buffered.new}
2121
let(:request) {Protocol::HTTP::Request.new("https", "example.com", "GET", "/", "http/1.1", Protocol::HTTP::Headers[{"accept" => "text/html"}], body)}
2222
let(:response) {adapter.call(request)}
2323

2424
with "set-cookie headers that has multiple values" do
25-
let(:app) {->(env) {[200, {"set-cookie" => "a=b\nx=y"}, []]}}
25+
let(:app) {->(env){[200, {"set-cookie" => "a=b\nx=y"}, []]}}
2626

2727
it "can make a response newline separated headers" do
2828
expect(response.headers["set-cookie"]).to be == ["a=b", "x=y"]
2929
end
3030
end
3131

3232
with "content-length header" do
33-
let(:app) {->(env) {[200, {"content-length" => "10"}, ["1234567890"]]}}
33+
let(:app) {->(env){[200, {"content-length" => "10"}, ["1234567890"]]}}
3434

3535
it "removes content-length header" do
3636
expect(response.headers).not.to be(:include?, "content-length")
3737
end
3838
end
3939

4040
with "connection: close header" do
41-
let(:app) {->(env) {[200, {"connection" => "close"}, []]}}
41+
let(:app) {->(env){[200, {"connection" => "close"}, []]}}
4242

4343
it "removes content-length header" do
4444
expect(response.headers).not.to be(:include?, "connection")
@@ -47,7 +47,7 @@
4747

4848
with "body that responds to #to_path" do
4949
let(:body) {Array.new}
50-
let(:app) {->(env) {[200, {}, body]}}
50+
let(:app) {->(env){[200, {}, body]}}
5151

5252
it "should generate file body" do
5353
expect(body).to receive(:to_path).and_return("/dev/null")
@@ -56,7 +56,7 @@
5656
end
5757

5858
with "206 partial response status" do
59-
let(:app) {->(env) {[200, {}, body]}}
59+
let(:app) {->(env){[200, {}, body]}}
6060

6161
it "should not modify partial responses" do
6262
expect(response.body).to be_a(Protocol::Rack::Body::Enumerable)
@@ -75,7 +75,7 @@
7575

7676
with "response handling" do
7777
with "array response" do
78-
let(:app) {->(env) {[200, {}, ["Hello"]]}}
78+
let(:app) {->(env){[200, {}, ["Hello"]]}}
7979

8080
it "handles array response correctly" do
8181
expect(response.body).to be_a(Protocol::Rack::Body::Enumerable)
@@ -85,31 +85,31 @@
8585

8686
with "header transformation" do
8787
with "array values" do
88-
let(:app) {->(env) {[200, {"x-custom" => "a\nb"}, []]}}
88+
let(:app) {->(env){[200, {"x-custom" => "a\nb"}, []]}}
8989

9090
it "joins array values with newlines in response" do
9191
expect(response.headers["x-custom"]).to be == ["a", "b"]
9292
end
9393
end
9494

9595
with "non-array values" do
96-
let(:app) {->(env) {[200, {"x-custom" => "value"}, []]}}
96+
let(:app) {->(env){[200, {"x-custom" => "value"}, []]}}
9797

9898
it "preserves non-array values" do
9999
expect(response.headers["x-custom"]).to be == ["value"]
100100
end
101101
end
102102

103103
with "multiple set-cookie headers" do
104-
let(:app) {->(env) {[200, {"set-cookie" => "a=b\nx=y"}, []]}}
104+
let(:app) {->(env){[200, {"set-cookie" => "a=b\nx=y"}, []]}}
105105

106106
it "joins set-cookie headers with newlines" do
107107
expect(response.headers["set-cookie"]).to be == ["a=b", "x=y"]
108108
end
109109
end
110110

111111
with "rack specific headers" do
112-
let(:app) {->(env) {[200, {"rack.hijack" => ->(stream){}}, []]}}
112+
let(:app) {->(env){[200, {"rack.hijack" => ->(stream){}}, []]}}
113113

114114
it "preserves rack specific headers in meta" do
115115
expect(response.headers).not.to be(:include?, "rack.hijack")
@@ -149,7 +149,7 @@
149149
let(:adapter) {subject.new(app)}
150150

151151
let(:callback_called) {false}
152-
let(:callback) {->(env, status, headers, exception) {@callback_called = true}}
152+
let(:callback) {->(env, status, headers, exception){@callback_called = true}}
153153
let(:app) do
154154
proc do |env|
155155
env[Protocol::Rack::RACK_RESPONSE_FINISHED] = [callback]

test/protocol/rack/adapter/rack3.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@
1212
include Sus::Fixtures::Console::CapturedLogger
1313

1414
with "#call" do
15-
let(:app) {->(env) {[200, {}, []]}}
15+
let(:app) {->(env){[200, {}, []]}}
1616
let(:adapter) {subject.new(app)}
1717

1818
let(:body) {Protocol::HTTP::Body::Buffered.new}
1919
let(:request) {Protocol::HTTP::Request.new("https", "example.com", "GET", "/", "http/1.1", Protocol::HTTP::Headers[{"accept" => "text/html"}], body)}
2020
let(:response) {adapter.call(request)}
2121

2222
with "set-cookie headers that has multiple values" do
23-
let(:app) {->(env) {[200, {"set-cookie" => ["a=b", "x=y"]}, []]}}
23+
let(:app) {->(env){[200, {"set-cookie" => ["a=b", "x=y"]}, []]}}
2424

2525
it "can make a response newline separated headers" do
2626
expect(response.headers["set-cookie"]).to be == ["a=b", "x=y"]
2727
end
2828
end
2929

3030
with "content-length header" do
31-
let(:app) {->(env) {[200, {"content-length" => "10"}, ["1234567890"]]}}
31+
let(:app) {->(env){[200, {"content-length" => "10"}, ["1234567890"]]}}
3232

3333
it "removes content-length header" do
3434
expect(response.headers).not.to be(:include?, "content-length")
3535
end
3636
end
3737

3838
with "connection: close header" do
39-
let(:app) {->(env) {[200, {"connection" => "close"}, []]}}
39+
let(:app) {->(env){[200, {"connection" => "close"}, []]}}
4040

4141
it "removes content-length header" do
4242
expect(response.headers).not.to be(:include?, "connection")
@@ -45,7 +45,7 @@
4545

4646
with "body that responds to #to_path" do
4747
let(:fake_file) {Array.new}
48-
let(:app) {->(env) {[200, {}, fake_file]}}
48+
let(:app) {->(env){[200, {}, fake_file]}}
4949

5050
it "should generate file body" do
5151
expect(fake_file).to receive(:to_path).and_return("/dev/null")
@@ -54,7 +54,7 @@
5454
end
5555

5656
with "206 partial response status" do
57-
let(:app) {->(env) {[200, {}, fake_file]}}
57+
let(:app) {->(env){[200, {}, fake_file]}}
5858

5959
it "should not modify partial responses" do
6060
expect(response.body).to be(:kind_of?, Protocol::Rack::Body::Enumerable)
@@ -64,7 +64,7 @@
6464

6565
with "a request that has response finished callbacks" do
6666
let(:callback) {->(env, status, headers, error){}}
67-
let(:app) {->(env) {env["rack.response_finished"] << callback; [200, {}, ["Hello World!"]]}}
67+
let(:app) {->(env){env["rack.response_finished"] << callback; [200, {}, ["Hello World!"]]}}
6868

6969
it "should call the callbacks" do
7070
expect(callback).to receive(:call)

0 commit comments

Comments
 (0)