Skip to content

Commit

Permalink
Merge pull request #670 from jnunemaker/rack-3
Browse files Browse the repository at this point in the history
Rack 3
  • Loading branch information
bkeepers authored Aug 1, 2023
2 parents 3363e51 + 175bce7 commit 65726db
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 19 deletions.
7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ Dir['flipper-*.gemspec'].each do |gemspec|
end

gem 'debug'
gem 'rake', '~> 12.3.3'
gem 'rake'
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.0'}"
gem 'rails', "~> #{ENV['RAILS_VERSION'] || '7.0.4'}"
gem 'minitest', '~> 5.18'
gem 'minitest-documentation'
gem 'webmock', '~> 3.0'
gem 'webmock'
gem 'ice_age'
gem 'redis-namespace'
gem 'webrick'
Expand Down
2 changes: 1 addition & 1 deletion flipper-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion flipper-ui.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<= 4.0.0'
gem.add_dependency 'flipper', "~> #{Flipper::VERSION}"
gem.add_dependency 'erubi', '>= 1.0.0', '< 2.0.0'
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/flipper/api/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]]
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/cloud/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/flipper/ui/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,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)]
Expand Down Expand Up @@ -158,20 +158,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 = case object
when String
object
Expand All @@ -186,7 +186,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

Expand Down
4 changes: 2 additions & 2 deletions spec/flipper/api/action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 65726db

Please sign in to comment.