From 279e85941d3ee9871b6def05743c4746aed48318 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Thu, 6 Oct 2022 11:29:44 -0400 Subject: [PATCH 1/3] Updates to make rack 3 work hopefully Can't fully test until rack 3 is in rails. --- Gemfile | 10 +++++----- flipper-api.gemspec | 2 +- flipper-ui.gemspec | 2 +- lib/flipper/api.rb | 2 +- lib/flipper/api/action.rb | 4 ++-- lib/flipper/cloud.rb | 2 +- lib/flipper/cloud/middleware.rb | 2 +- lib/flipper/ui.rb | 2 +- lib/flipper/ui/action.rb | 12 ++++++------ 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index 8e0bfb1ec..6977f5018 100644 --- a/Gemfile +++ b/Gemfile @@ -7,16 +7,16 @@ Dir['flipper-*.gemspec'].each do |gemspec| end gem 'debug' -gem 'rake', '~> 12.3.3' -gem 'shotgun', '~> 0.9' +gem 'rake' +gem 'shotgun' gem 'statsd-ruby', '~> 1.2.1' gem 'rspec', '~> 3.0' -gem 'rack-test', '~> 0.6.3' +gem 'rack-test' gem 'sqlite3', "~> #{ENV['SQLITE3_VERSION'] || '1.4.1'}" -gem 'rails', "~> #{ENV['RAILS_VERSION'] || '7.0.0'}" +gem 'rails', "~> #{ENV['RAILS_VERSION'] || '7.0.4'}" gem 'minitest', '~> 5.8' gem 'minitest-documentation' -gem 'webmock', '~> 3.0' +gem 'webmock' gem 'ice_age' gem 'redis-namespace' gem 'webrick' diff --git a/flipper-api.gemspec b/flipper-api.gemspec index 35842f27f..c0cc6b915 100644 --- a/flipper-api.gemspec +++ b/flipper-api.gemspec @@ -19,6 +19,6 @@ Gem::Specification.new do |gem| gem.version = Flipper::VERSION gem.metadata = Flipper::METADATA - gem.add_dependency 'rack', '>= 1.4', '< 3' + gem.add_dependency 'rack', '>= 1.4', '< 4' gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" end diff --git a/flipper-ui.gemspec b/flipper-ui.gemspec index c298a08d7..5f9394230 100644 --- a/flipper-ui.gemspec +++ b/flipper-ui.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |gem| gem.version = Flipper::VERSION gem.metadata = Flipper::METADATA - gem.add_dependency 'rack', '>= 1.4', '< 3' + gem.add_dependency 'rack', '>= 1.4', '< 4' gem.add_dependency 'rack-protection', '>= 1.5.3', '<= 2.3.0' gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" gem.add_dependency 'erubi', '>= 1.0.0', '< 2.0.0' diff --git a/lib/flipper/api.rb b/lib/flipper/api.rb index 109263675..bc9c3ba93 100644 --- a/lib/flipper/api.rb +++ b/lib/flipper/api.rb @@ -9,7 +9,7 @@ module Api def self.app(flipper = nil, options = {}) env_key = options.fetch(:env_key, 'flipper') - app = ->(_) { [404, { 'Content-Type'.freeze => CONTENT_TYPE }, ['{}'.freeze]] } + app = ->(_) { [404, { 'content-type'.freeze => CONTENT_TYPE }, ['{}'.freeze]] } builder = Rack::Builder.new yield builder if block_given? builder.use Flipper::Api::JsonParams diff --git a/lib/flipper/api/action.rb b/lib/flipper/api/action.rb index bfd684c76..056ab7c9c 100644 --- a/lib/flipper/api/action.rb +++ b/lib/flipper/api/action.rb @@ -68,7 +68,7 @@ def initialize(flipper, request) @flipper = flipper @request = request @code = 200 - @headers = { 'Content-Type' => Api::CONTENT_TYPE } + @headers = { 'content-type' => Api::CONTENT_TYPE } end # Public: Runs the request method for the provided request. @@ -113,7 +113,7 @@ def halt(response) # status - http status code def json_response(object, status = 200) - header 'Content-Type', Api::CONTENT_TYPE + header 'content-type', Api::CONTENT_TYPE status(status) body = JSON.dump(object) halt [@code, @headers, [body]] diff --git a/lib/flipper/cloud.rb b/lib/flipper/cloud.rb index 42ed0be87..dbb46d228 100644 --- a/lib/flipper/cloud.rb +++ b/lib/flipper/cloud.rb @@ -25,7 +25,7 @@ def self.app(flipper = nil, options = {}) env_key = options.fetch(:env_key, 'flipper') memoizer_options = options.fetch(:memoizer_options, {}) - app = ->(_) { [404, { 'Content-Type'.freeze => 'application/json'.freeze }, ['{}'.freeze]] } + app = ->(_) { [404, { 'content-type'.freeze => 'application/json'.freeze }, ['{}'.freeze]] } builder = Rack::Builder.new yield builder if block_given? builder.use Flipper::Middleware::SetupEnv, flipper, env_key: env_key diff --git a/lib/flipper/cloud/middleware.rb b/lib/flipper/cloud/middleware.rb index 7a0e8d635..35d89c5b8 100644 --- a/lib/flipper/cloud/middleware.rb +++ b/lib/flipper/cloud/middleware.rb @@ -24,7 +24,7 @@ def call!(env) if request.post? && (request.path_info.match(ROOT_PATH) || request.path_info.match(WEBHOOK_PATH)) status = 200 headers = { - "Content-Type" => "application/json", + "content-type" => "application/json", } body = "{}" payload = request.body.read diff --git a/lib/flipper/ui.rb b/lib/flipper/ui.rb index 81b48f9eb..3e4b4a70b 100644 --- a/lib/flipper/ui.rb +++ b/lib/flipper/ui.rb @@ -22,7 +22,7 @@ def self.app(flipper = nil, options = {}) env_key = options.fetch(:env_key, 'flipper') rack_protection_options = options.fetch(:rack_protection, use: :authenticity_token) - app = ->(_) { [200, { 'Content-Type' => 'text/html' }, ['']] } + app = ->(_) { [200, { 'content-type' => 'text/html' }, ['']] } builder = Rack::Builder.new yield builder if block_given? builder.use Rack::Protection, rack_protection_options diff --git a/lib/flipper/ui/action.rb b/lib/flipper/ui/action.rb index 81c3c679a..834e9e96d 100644 --- a/lib/flipper/ui/action.rb +++ b/lib/flipper/ui/action.rb @@ -110,7 +110,7 @@ def initialize(flipper, request) @flipper = flipper @request = request @code = 200 - @headers = { 'Content-Type' => 'text/plain' } + @headers = { 'content-type' => 'text/plain' } @breadcrumbs = if Flipper::UI.configuration.application_breadcrumb_href [Breadcrumb.new('App', Flipper::UI.configuration.application_breadcrumb_href)] @@ -160,20 +160,20 @@ def halt(response) # # Returns a response. def view_response(name) - header 'Content-Type', 'text/html' - header 'Content-Security-Policy', CONTENT_SECURITY_POLICY + header 'content-type', 'text/html' + header 'content-security-policy', CONTENT_SECURITY_POLICY body = view_with_layout { view_without_layout name } halt [@code, @headers, [body]] end # Public: Dumps an object as json and returns rack response with that as - # the body. Automatically sets Content-Type to "application/json". + # the body. Automatically sets content-type to "application/json". # # object - The Object that should be dumped as json. # # Returns a response. def json_response(object) - header 'Content-Type', 'application/json' + header 'content-type', 'application/json' body = JSON.dump(object) halt [@code, @headers, [body]] end @@ -183,7 +183,7 @@ def json_response(object) # location - The String location to set the Location header to. def redirect_to(location) status 302 - header 'Location', "#{script_name}#{Rack::Utils.escape_path(location)}" + header 'location', "#{script_name}#{Rack::Utils.escape_path(location)}" halt [@code, @headers, ['']] end From deaf4024391d568b2d4ae099ef1d039f31b3cd89 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Thu, 6 Oct 2022 11:33:47 -0400 Subject: [PATCH 2/3] Add rackup as that is moved to separate gem in rack 3 and its used in examples --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 6977f5018..0f6368879 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,7 @@ gem 'shotgun' gem 'statsd-ruby', '~> 1.2.1' gem 'rspec', '~> 3.0' gem 'rack-test' +gem 'rackup' gem 'sqlite3', "~> #{ENV['SQLITE3_VERSION'] || '1.4.1'}" gem 'rails', "~> #{ENV['RAILS_VERSION'] || '7.0.4'}" gem 'minitest', '~> 5.8' From 175bce7de921bc1db75a5f4309c82089e3299db1 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Tue, 1 Aug 2023 10:14:16 -0400 Subject: [PATCH 3/3] Fix API spec --- spec/flipper/api/action_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/flipper/api/action_spec.rb b/spec/flipper/api/action_spec.rb index fdbc83942..7fd17fa89 100644 --- a/spec/flipper/api/action_spec.rb +++ b/spec/flipper/api/action_spec.rb @@ -67,7 +67,7 @@ def delete status, headers, body = response parsed_body = JSON.parse(body[0]) - expect(headers['Content-Type']).to eq('application/json') + expect(headers['content-type']).to eq('application/json') expect(parsed_body).to eql(api_not_found_response) end end @@ -81,7 +81,7 @@ def delete status, headers, body = response parsed_body = JSON.parse(body[0]) - expect(headers['Content-Type']).to eq('application/json') + expect(headers['content-type']).to eq('application/json') expect(parsed_body['code']).to eq(2) expect(parsed_body['message']).to eq('Group not registered.') expect(parsed_body['more_info']).to eq(api_error_code_reference_url)