Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Rack 3 #92

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ orbs:
jobs:
ruby-test:
machine:
image: circleci/classic:201808-01 # docker 18.06.0-ce, docker-compose 1.22.0
image: ubuntu-2204:2024.01.1
steps:
- gusto/bundle-install
- run: bundle exec rake
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.5.7
3.3.0
145 changes: 76 additions & 69 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,110 @@ PATH
remote: .
specs:
grpc-web (1.2.1)
base64
grpc (~> 1.0)
rack (>= 1.6.0, < 3.0)
rack (>= 1.6.0)

GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
apparition (0.1.0)
backports
capybara (~> 3.12, < 4)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
apparition (0.6.0)
capybara (~> 3.13, < 4)
websocket-driver (>= 0.6.5)
ast (2.4.0)
backports (3.15.0)
byebug (11.0.1)
capybara (3.15.1)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.6)
byebug (11.1.3)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.2)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
coderay (1.1.2)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
docile (1.3.2)
google-protobuf (3.13.0)
googleapis-common-protos-types (1.0.5)
google-protobuf (~> 3.11)
grpc (1.32.0)
google-protobuf (~> 3.13)
coderay (1.1.3)
crack (1.0.0)
bigdecimal
rexml
diff-lcs (1.5.1)
docile (1.4.0)
google-protobuf (3.25.3)
googleapis-common-protos-types (1.13.0)
google-protobuf (~> 3.18)
grpc (1.62.0)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
hashdiff (1.0.0)
jaro_winkler (1.5.4)
json (2.3.0)
method_source (0.9.2)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
nokogiri (1.10.8)
mini_portile2 (~> 2.4.0)
parallel (1.19.1)
parser (2.7.0.2)
ast (~> 2.4.0)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.7.0)
hashdiff (1.1.0)
jaro_winkler (1.5.6)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
nokogiri (1.16.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (~> 0.10)
public_suffix (4.0.1)
rack (2.0.9)
rack-cors (1.1.0)
pry (>= 0.13, < 0.15)
public_suffix (5.0.4)
racc (1.7.3)
rack (3.0.9.1)
rack-cors (2.0.2)
rack (>= 2.0.0)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rainbow (3.0.0)
rake (13.0.1)
regexp_parser (1.6.0)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.0)
rspec-support (~> 3.9.0)
rspec-expectations (3.9.0)
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.1.1)
rake (13.1.0)
regexp_parser (2.9.0)
rexml (3.2.6)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (0.79.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
rubocop-rspec (1.37.1)
rubocop-rspec (1.41.0)
rubocop (>= 0.68.1)
ruby-progressbar (1.10.1)
safe_yaml (1.0.5)
simplecov (0.17.1)
ruby-progressbar (1.13.0)
simplecov (0.22.0)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
unicode-display_width (1.6.1)
webmock (3.8.2)
addressable (>= 2.3.6)
webmock (3.23.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket-driver (0.7.1)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)

Expand All @@ -118,4 +125,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
2.1.4
2.5.6
3 changes: 2 additions & 1 deletion grpc-web.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ Gem::Specification.new do |spec|
spec.files = Dir['lib/**/*']
spec.require_paths = ['lib']

spec.add_dependency 'base64'
spec.add_dependency 'grpc', '~> 1.0'
spec.add_dependency 'rack', '>= 1.6.0', '< 3.0'
spec.add_dependency 'rack', '>= 1.6.0'

spec.add_development_dependency 'apparition'
spec.add_development_dependency 'pry-byebug'
Expand Down
2 changes: 1 addition & 1 deletion lib/grpc_web/client/client_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def request(uri, rpc_desc, params = {}, metadata = {})
def request_headers(metadata)
{
'Accept' => PROTO_CONTENT_TYPE,
'Content-Type' => PROTO_CONTENT_TYPE,
'content-type' => PROTO_CONTENT_TYPE,
}.merge(metadata[:metadata] || {})
end

Expand Down
10 changes: 5 additions & 5 deletions lib/grpc_web/server/rack_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def call(service, service_method, env)
request = GRPCWeb::GRPCWebRequest.new(service, service_method, content_type, accept, body)
response = GRPCWeb::GRPCRequestProcessor.process(request)

[200, { 'Content-Type' => response.content_type }, [response.body]]
[200, { 'content-type' => response.content_type }, [response.body]]
rescue Google::Protobuf::ParseError => e
invalid_response(e.message)
rescue StandardError => e
Expand All @@ -51,27 +51,27 @@ def valid_content_types?(rack_request)
def not_found_response(path)
[
NOT_FOUND,
{ 'Content-Type' => 'text/plain', 'X-Cascade' => 'pass' },
{ 'content-type' => 'text/plain', 'x-cascade' => 'pass' },
["Not Found: #{path}"],
]
end

def unsupported_media_type_response
[
UNSUPPORTED_MEDIA_TYPE,
{ 'Content-Type' => 'text/plain' },
{ 'content-type' => 'text/plain' },
['Unsupported Media Type: Invalid Content-Type or Accept header'],
]
end

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

def error_response
[
INTERNAL_SERVER_ERROR,
{ 'Content-Type' => 'text/plain' },
{ 'content-type' => 'text/plain' },
['Request failed with an unexpected error.'],
]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/envoy_server_ruby_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def say_hello(_request, _metadata = nil)
end

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

let(:service) do
Class.new(TestHelloService) do
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/grpc_web/client/client_executor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
let(:expected_headers) do
{
'Accept' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
'Content-Type' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
'content-type' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
}
end

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

let(:custom_header) { { metadata: { 'Custom-header' => 'Meow meow' } } }
let(:custom_header) { { metadata: { 'custom-header' => 'Meow meow' } } }
let(:expected_headers) do
{
'Accept' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
'Content-Type' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
'content-type' => GRPCWeb::ContentTypes::PROTO_CONTENT_TYPE,
'Custom-header' => 'Meow meow',
}
end
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/grpc_web/server/rack_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
it 'returns a 200' do
expect(call).to eq([
200,
{ 'Content-Type' => response_content_type },
{ 'content-type' => response_content_type },
[response_body],
])
end
Expand All @@ -63,7 +63,7 @@
it 'returns a 404' do
expect(call).to eq([
404,
{ 'Content-Type' => 'text/plain', 'X-Cascade' => 'pass' },
{ 'content-type' => 'text/plain', 'x-cascade' => 'pass' },
["Not Found: #{path_info}"],
])
end
Expand All @@ -75,7 +75,7 @@
it 'returns a 415' do
expect(call).to eq([
415,
{ 'Content-Type' => 'text/plain' },
{ 'content-type' => 'text/plain' },
['Unsupported Media Type: Invalid Content-Type or Accept header'],
])
end
Expand All @@ -87,7 +87,7 @@
it 'returns a 415' do
expect(call).to eq([
415,
{ 'Content-Type' => 'text/plain' },
{ 'content-type' => 'text/plain' },
['Unsupported Media Type: Invalid Content-Type or Accept header'],
])
end
Expand All @@ -104,7 +104,7 @@
it 'returns a 422' do
expect(call).to eq([
422,
{ 'Content-Type' => 'text/plain' },
{ 'content-type' => 'text/plain' },
["Invalid request format: #{error_message}"],
])
end
Expand All @@ -120,7 +120,7 @@
it 'returns a 500' do
expect(call).to eq([
500,
{ 'Content-Type' => 'text/plain' },
{ 'content-type' => 'text/plain' },
['Request failed with an unexpected error.'],
])
end
Expand Down
1 change: 1 addition & 0 deletions spec/unit/grpc_web/server/text_coder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'base64'
require 'grpc_web/server/text_coder'

RSpec.describe GRPCWeb::TextCoder do
Expand Down