Skip to content

Commit f5bbc0b

Browse files
nganjoemsak
authored andcommitted
Support Rack 3
1 parent 0334b88 commit f5bbc0b

File tree

8 files changed

+22
-19
lines changed

8 files changed

+22
-19
lines changed

Gemfile.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ PATH
22
remote: .
33
specs:
44
grpc-web (1.2.1)
5+
base64
56
google-protobuf (~> 3.13.0)
67
grpc (~> 1.0)
7-
rack (>= 1.6.0, < 3.0)
8+
rack (~> 3.0)
89

910
GEM
1011
remote: https://rubygems.org/
@@ -70,7 +71,7 @@ GEM
7071
pry (>= 0.13, < 0.15)
7172
public_suffix (5.1.1)
7273
racc (1.8.1)
73-
rack (2.2.13)
74+
rack (3.1.12)
7475
rack-cors (2.0.2)
7576
rack (>= 2.0.0)
7677
rack-test (2.2.0)

grpc-web.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ Gem::Specification.new do |spec|
2020
spec.files = Dir['lib/**/*']
2121
spec.require_paths = ['lib']
2222

23+
spec.add_dependency 'base64'
2324
spec.add_dependency 'grpc', '~> 1.0'
2425
spec.add_dependency 'google-protobuf', '~> 3.13.0'
25-
spec.add_dependency 'rack', '>= 1.6.0', '< 3.0'
26+
spec.add_dependency 'rack', '~> 3.0'
2627

2728
spec.add_development_dependency 'apparition'
2829
spec.add_development_dependency 'pry-byebug'

lib/grpc_web/client/client_executor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def request(uri, rpc_desc, params = {}, metadata = {})
3232
def request_headers(metadata)
3333
{
3434
'Accept' => PROTO_CONTENT_TYPE,
35-
'Content-Type' => PROTO_CONTENT_TYPE,
35+
'content-type' => PROTO_CONTENT_TYPE,
3636
}.merge(metadata[:metadata] || {})
3737
end
3838

lib/grpc_web/server/rack_handler.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def call(service, service_method, env)
2929
request = GRPCWeb::GRPCWebRequest.new(service, service_method, content_type, accept, body)
3030
response = GRPCWeb::GRPCRequestProcessor.process(request)
3131

32-
[200, { 'Content-Type' => response.content_type }, [response.body]]
32+
[200, { 'content-type' => response.content_type }, [response.body]]
3333
rescue Google::Protobuf::ParseError => e
3434
invalid_response(e.message)
3535
rescue StandardError => e
@@ -51,27 +51,27 @@ def valid_content_types?(rack_request)
5151
def not_found_response(path)
5252
[
5353
NOT_FOUND,
54-
{ 'Content-Type' => 'text/plain', 'X-Cascade' => 'pass' },
54+
{ 'content-type' => 'text/plain', 'x-cascade' => 'pass' },
5555
["Not Found: #{path}"],
5656
]
5757
end
5858

5959
def unsupported_media_type_response
6060
[
6161
UNSUPPORTED_MEDIA_TYPE,
62-
{ 'Content-Type' => 'text/plain' },
62+
{ 'content-type' => 'text/plain' },
6363
['Unsupported Media Type: Invalid Content-Type or Accept header'],
6464
]
6565
end
6666

6767
def invalid_response(message)
68-
[422, { 'Content-Type' => 'text/plain' }, ["Invalid request format: #{message}"]]
68+
[422, { 'content-type' => 'text/plain' }, ["Invalid request format: #{message}"]]
6969
end
7070

7171
def error_response
7272
[
7373
INTERNAL_SERVER_ERROR,
74-
{ 'Content-Type' => 'text/plain' },
74+
{ 'content-type' => 'text/plain' },
7575
['Request failed with an unexpected error.'],
7676
]
7777
end

spec/integration/envoy_server_ruby_client_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def say_hello(_request, _metadata = nil)
9797
end
9898

9999
context 'with a custom header' do
100-
subject { client.say_hello({ name: name }, metadata: { 'Custom-header' => 'Meow meow' }) }
100+
subject { client.say_hello({ name: name }, metadata: { 'custom-header' => 'Meow meow' }) }
101101

102102
let(:service) do
103103
Class.new(TestHelloService) do

spec/unit/grpc_web/client/client_executor_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
let(:expected_headers) do
2525
{
2626
'Accept' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
27-
'Content-Type' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
27+
'content-type' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
2828
}
2929
end
3030

@@ -68,11 +68,11 @@
6868
context 'with custom header' do
6969
subject(:response) { described_class.request(request_uri, rpc_desc, params, custom_header) }
7070

71-
let(:custom_header) { { metadata: { 'Custom-header' => 'Meow meow' } } }
71+
let(:custom_header) { { metadata: { 'custom-header' => 'Meow meow' } } }
7272
let(:expected_headers) do
7373
{
7474
'Accept' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
75-
'Content-Type' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
75+
'content-type' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
7676
'Custom-header' => 'Meow meow',
7777
}
7878
end

spec/unit/grpc_web/server/rack_handler_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
it 'returns a 200' do
3939
expect(call).to eq([
4040
200,
41-
{ 'Content-Type' => response_content_type },
41+
{ 'content-type' => response_content_type },
4242
[response_body],
4343
])
4444
end
@@ -63,7 +63,7 @@
6363
it 'returns a 404' do
6464
expect(call).to eq([
6565
404,
66-
{ 'Content-Type' => 'text/plain', 'X-Cascade' => 'pass' },
66+
{ 'content-type' => 'text/plain', 'x-cascade' => 'pass' },
6767
["Not Found: #{path_info}"],
6868
])
6969
end
@@ -75,7 +75,7 @@
7575
it 'returns a 415' do
7676
expect(call).to eq([
7777
415,
78-
{ 'Content-Type' => 'text/plain' },
78+
{ 'content-type' => 'text/plain' },
7979
['Unsupported Media Type: Invalid Content-Type or Accept header'],
8080
])
8181
end
@@ -87,7 +87,7 @@
8787
it 'returns a 415' do
8888
expect(call).to eq([
8989
415,
90-
{ 'Content-Type' => 'text/plain' },
90+
{ 'content-type' => 'text/plain' },
9191
['Unsupported Media Type: Invalid Content-Type or Accept header'],
9292
])
9393
end
@@ -104,7 +104,7 @@
104104
it 'returns a 422' do
105105
expect(call).to eq([
106106
422,
107-
{ 'Content-Type' => 'text/plain' },
107+
{ 'content-type' => 'text/plain' },
108108
["Invalid request format: #{error_message}"],
109109
])
110110
end
@@ -120,7 +120,7 @@
120120
it 'returns a 500' do
121121
expect(call).to eq([
122122
500,
123-
{ 'Content-Type' => 'text/plain' },
123+
{ 'content-type' => 'text/plain' },
124124
['Request failed with an unexpected error.'],
125125
])
126126
end

spec/unit/grpc_web/server/text_coder_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'base64'
34
require 'grpc_web/server/text_coder'
45

56
RSpec.describe GRPCWeb::TextCoder do

0 commit comments

Comments
 (0)