Skip to content

Fix default response headers to work with Rack 3 #2455

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

Merged
merged 8 commits into from
Jun 20, 2024
Merged
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
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ jobs:
- ruby: '3.3'
gemfile: gemfiles/dry_validation.gemfile
specs: 'spec/integration/dry_validation'
- ruby: '3.3'
gemfile: gemfiles/rails_6_1.gemfile
specs: 'spec/integration/rails'
- ruby: '3.3'
gemfile: gemfiles/rails_7_0.gemfile
specs: 'spec/integration/rails'
- ruby: '3.3'
gemfile: gemfiles/rails_7_1.gemfile
specs: 'spec/integration/rails'
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#### Fixes

* [#2453](https://github.com/ruby-grape/grape/pull/2453): Fix context in rescue_from - [@ericproulx](https://github.com/ericproulx).
* [#2455](https://github.com/ruby-grape/grape/pull/2455): Fix default response headers to work with Rack 3 - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

### 2.1.0 (2024/06/15)
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ FROM ruby:$RUBY_VERSION-alpine
ENV BUNDLE_PATH /usr/local/bundle/gems
ENV LIB_PATH /var/grape

RUN apk add --update --no-cache make gcc git libc-dev && \
RUN apk add --update --no-cache make gcc git libc-dev gcompat && \
gem update --system && gem install bundler

WORKDIR $LIB_PATH

COPY /docker/entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]
ENTRYPOINT ["docker-entrypoint.sh"]
1 change: 1 addition & 0 deletions gemfiles/rails_6_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
eval_gemfile '../Gemfile'

gem 'rails', '~> 6.0.0'
gem 'tzinfo-data', require: false
1 change: 1 addition & 0 deletions gemfiles/rails_6_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
eval_gemfile '../Gemfile'

gem 'rails', '~> 6.1'
gem 'tzinfo-data', require: false
1 change: 1 addition & 0 deletions gemfiles/rails_7_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
eval_gemfile '../Gemfile'

gem 'rails', '~> 7.0.0'
gem 'tzinfo-data', require: false
1 change: 1 addition & 0 deletions gemfiles/rails_7_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
eval_gemfile '../Gemfile'

gem 'rails', '~> 7.1.0'
gem 'tzinfo-data', require: false
1 change: 1 addition & 0 deletions gemfiles/rails_edge.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
eval_gemfile '../Gemfile'

gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', require: false
3 changes: 2 additions & 1 deletion lib/grape/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def with_optimization
end

def default_response
[404, { Grape::Http::Headers::X_CASCADE => 'pass' }, ['404 Not Found']]
headers = Grape::Util::Header.new.merge(Grape::Http::Headers::X_CASCADE => 'pass')
[404, headers, ['404 Not Found']]
end

def match?(input, method)
Expand Down
20 changes: 0 additions & 20 deletions spec/grape/railtie_spec.rb

This file was deleted.

51 changes: 51 additions & 0 deletions spec/integration/rails/mounting_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

describe 'Rails', if: defined?(Rails) do
context 'rails mounted' do
let(:api) do
Class.new(Grape::API) do
get('/test_grape') { 'rails mounted' }
end
end

let(:app) do
require 'rails'
require 'action_controller/railtie'

# https://github.com/rails/rails/issues/51784
# same error as described if not redefining the following
ActiveSupport::Dependencies.autoload_paths = []
ActiveSupport::Dependencies.autoload_once_paths = []

Class.new(Rails::Application) do
config.eager_load = false
config.load_defaults "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"
config.api_only = true
config.consider_all_requests_local = true
config.hosts << 'example.org'

routes.append do
mount GrapeApi => '/'

get 'up', to: lambda { |_env|
['200', {}, ['hello world']]
}
end
end
end

before do
stub_const('GrapeApi', api)
app.initialize!
end

it 'cascades' do
get '/test_grape'
expect(last_response).to be_successful
expect(last_response.body).to eq('rails mounted')
get '/up'
expect(last_response).to be_successful
expect(last_response.body).to eq('hello world')
end
end
end
25 changes: 25 additions & 0 deletions spec/integration/rails/railtie_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

if defined?(Rails) && ActiveSupport.gem_version >= Gem::Version.new('7.1')
describe Grape::Railtie do
describe '.railtie' do
subject { test_app.deprecators[:grape] }

let(:test_app) do
# https://github.com/rails/rails/issues/51784
# same error as described if not redefining the following
ActiveSupport::Dependencies.autoload_paths = []
ActiveSupport::Dependencies.autoload_once_paths = []

Class.new(Rails::Application) do
config.eager_load = false
config.load_defaults "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"
end
end

before { test_app.initialize! }

it { is_expected.to be(Grape.deprecator) }
end
end
end