Skip to content

Commit 42aa6ab

Browse files
committed
Modernize code.
1 parent 0b858c7 commit 42aa6ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+212
-183
lines changed

.github/workflows/documentation-coverage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v6
1717
- uses: ruby/setup-ruby@v1
1818
with:
1919
ruby-version: ruby

.github/workflows/documentation.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
runs-on: ubuntu-latest
2525

2626
steps:
27-
- uses: actions/checkout@v4
27+
- uses: actions/checkout@v6
2828

2929
- uses: ruby/setup-ruby@v1
3030
with:
@@ -39,7 +39,7 @@ jobs:
3939
run: bundle exec bake utopia:project:static --force no
4040

4141
- name: Upload documentation artifact
42-
uses: actions/upload-pages-artifact@v3
42+
uses: actions/upload-pages-artifact@v4
4343
with:
4444
path: docs
4545

.github/workflows/rubocop.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@v6
1414
- uses: ruby/setup-ruby@v1
1515
with:
1616
ruby-version: ruby

.github/workflows/test-coverage.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- ruby
2424

2525
steps:
26-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v6
2727
- uses: ruby/setup-ruby@v1
2828
with:
2929
ruby-version: ${{matrix.ruby}}
@@ -33,7 +33,7 @@ jobs:
3333
timeout-minutes: 5
3434
run: bundle exec bake test
3535

36-
- uses: actions/upload-artifact@v4
36+
- uses: actions/upload-artifact@v5
3737
with:
3838
include-hidden-files: true
3939
if-no-files-found: error
@@ -45,13 +45,13 @@ jobs:
4545
runs-on: ubuntu-latest
4646

4747
steps:
48-
- uses: actions/checkout@v4
48+
- uses: actions/checkout@v6
4949
- uses: ruby/setup-ruby@v1
5050
with:
5151
ruby-version: ruby
5252
bundler-cache: true
5353

54-
- uses: actions/download-artifact@v4
54+
- uses: actions/download-artifact@v6
5555

5656
- name: Validate coverage
5757
timeout-minutes: 5

.github/workflows/test-external.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ jobs:
2020
- "3.2"
2121
- "3.3"
2222
- "3.4"
23+
- "4.0"
2324

2425
steps:
25-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v6
2627
- uses: ruby/setup-ruby@v1
2728
with:
2829
ruby-version: ${{matrix.ruby}}

.github/workflows/test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- "3.2"
2222
- "3.3"
2323
- "3.4"
24+
- "4.0"
2425

2526
experimental: [false]
2627

@@ -36,7 +37,7 @@ jobs:
3637
experimental: true
3738

3839
steps:
39-
- uses: actions/checkout@v4
40+
- uses: actions/checkout@v6
4041
- uses: ruby/setup-ruby@v1
4142
with:
4243
ruby-version: ${{matrix.ruby}}

.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

context/design-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,5 @@ interim_response_callback = proc do |status, headers|
205205
end
206206
end
207207

208-
response = client.post("/upload", {'expect' => '100-continue'}, body, interim_response: interim_response_callback)
208+
response = client.post("/upload", {"expect" => "100-continue"}, body, interim_response: interim_response_callback)
209209
```

context/getting-started.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This gem does not provide any specific client or server implementation, rather i
3434
{ruby Protocol::HTTP::Request} represents an HTTP request which can be used both server and client-side.
3535

3636
``` ruby
37-
require 'protocol/http/request'
37+
require "protocol/http/request"
3838

3939
# Short form (recommended):
4040
request = Protocol::HTTP::Request["GET", "/index.html", {"accept" => "text/html"}]
@@ -54,7 +54,7 @@ request.headers # => Protocol::HTTP::Headers instance
5454
{ruby Protocol::HTTP::Response} represents an HTTP response which can be used both server and client-side.
5555

5656
``` ruby
57-
require 'protocol/http/response'
57+
require "protocol/http/response"
5858

5959
# Short form (recommended):
6060
response = Protocol::HTTP::Response[200, {"content-type" => "text/html"}, "Hello, World!"]
@@ -83,15 +83,15 @@ response.failure? # => false (400-599)
8383
#### Basic Usage
8484

8585
``` ruby
86-
require 'protocol/http/headers'
86+
require "protocol/http/headers"
8787

8888
headers = Protocol::HTTP::Headers.new
8989

9090
# Assignment by title-case key:
91-
headers['Content-Type'] = "image/jpeg"
91+
headers["Content-Type"] = "image/jpeg"
9292

9393
# Lookup by lower-case (normalized) key:
94-
headers['content-type']
94+
headers["content-type"]
9595
# => "image/jpeg"
9696
```
9797

@@ -101,8 +101,8 @@ Many headers receive special semantic processing, automatically splitting comma-
101101

102102
``` ruby
103103
# Accept header with quality values:
104-
headers['Accept'] = 'text/html, application/json;q=0.8, */*;q=0.1'
105-
accept = headers['accept']
104+
headers["Accept"] = "text/html, application/json;q=0.8, */*;q=0.1"
105+
accept = headers["accept"]
106106
# => ["text/html", "application/json;q=0.8", "*/*;q=0.1"]
107107

108108
# Access parsed media ranges with quality factors:
@@ -114,17 +114,17 @@ end
114114
# */* (q=0.1)
115115

116116
# Accept-Encoding automatically splits values:
117-
headers['Accept-Encoding'] = 'gzip, deflate, br;q=0.9'
118-
headers['accept-encoding']
117+
headers["Accept-Encoding"] = "gzip, deflate, br;q=0.9"
118+
headers["accept-encoding"]
119119
# => ["gzip", "deflate", "br;q=0.9"]
120120

121121
# Cache-Control splits directives:
122-
headers['Cache-Control'] = 'max-age=3600, no-cache, must-revalidate'
123-
headers['cache-control']
122+
headers["Cache-Control"] = "max-age=3600, no-cache, must-revalidate"
123+
headers["cache-control"]
124124
# => ["max-age=3600", "no-cache", "must-revalidate"]
125125

126126
# Vary header normalizes field names to lowercase:
127-
headers['Vary'] = 'Accept-Encoding, User-Agent'
128-
headers['vary']
127+
headers["Vary"] = "Accept-Encoding, User-Agent"
128+
headers["vary"]
129129
# => ["accept-encoding", "user-agent"]
130130
```

context/headers.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ This guide explains how to work with HTTP headers using `protocol-http`.
1515
The {Protocol::HTTP::Headers} class provides a comprehensive interface for creating and manipulating HTTP headers:
1616

1717
```ruby
18-
require 'protocol/http'
18+
require "protocol/http"
1919

2020
headers = Protocol::HTTP::Headers.new
21-
headers.add('content-type', 'text/html')
22-
headers.add('set-cookie', 'session=abc123')
21+
headers.add("content-type", "text/html")
22+
headers.add("set-cookie", "session=abc123")
2323

2424
# Access headers
25-
content_type = headers['content-type'] # => "text/html"
25+
content_type = headers["content-type"] # => "text/html"
2626

2727
# Check if header exists
28-
headers.include?('content-type') # => true
28+
headers.include?("content-type") # => true
2929
```
3030

3131
### Header Policies
@@ -34,11 +34,11 @@ Different header types have different behaviors for merging, validation, and tra
3434

3535
```ruby
3636
# Some headers can be specified multiple times
37-
headers.add('set-cookie', 'first=value1')
38-
headers.add('set-cookie', 'second=value2')
37+
headers.add("set-cookie", "first=value1")
38+
headers.add("set-cookie", "second=value2")
3939

4040
# Others are singletons and will raise errors if duplicated
41-
headers.add('content-length', '100')
41+
headers.add("content-length", "100")
4242
# headers.add('content-length', '200') # Would raise DuplicateHeaderError
4343
```
4444

@@ -48,11 +48,11 @@ Some headers have specialized classes for parsing and formatting:
4848

4949
```ruby
5050
# Accept header with media ranges
51-
accept = Protocol::HTTP::Header::Accept.new('text/html,application/json;q=0.9')
51+
accept = Protocol::HTTP::Header::Accept.new("text/html,application/json;q=0.9")
5252
media_ranges = accept.media_ranges
5353

5454
# Authorization header
55-
auth = Protocol::HTTP::Header::Authorization.basic('username', 'password')
55+
auth = Protocol::HTTP::Header::Authorization.basic("username", "password")
5656
# => "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
5757
```
5858

@@ -63,20 +63,20 @@ HTTP trailers are headers that appear after the message body. For security reaso
6363
```ruby
6464
# Working with trailers
6565
headers = Protocol::HTTP::Headers.new([
66-
['content-type', 'text/html'],
67-
['content-length', '1000']
66+
["content-type", "text/html"],
67+
["content-length", "1000"]
6868
])
6969

7070
# Start trailer section
7171
headers.trailer!
7272

7373
# These will be allowed (safe metadata)
74-
headers.add('etag', '"12345"')
75-
headers.add('date', Time.now.httpdate)
74+
headers.add("etag", '"12345"')
75+
headers.add("date", Time.now.httpdate)
7676

7777
# These will be silently ignored for security
78-
headers.add('authorization', 'Bearer token') # Ignored - credential leakage risk
79-
headers.add('connection', 'close') # Ignored - hop-by-hop header
78+
headers.add("authorization", "Bearer token") # Ignored - credential leakage risk
79+
headers.add("connection", "close") # Ignored - hop-by-hop header
8080
```
8181

8282
The trailer security system prevents HTTP request smuggling by restricting which headers can appear in trailers:

0 commit comments

Comments
 (0)