Skip to content
New issue

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

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

Already on GitHub? # to your account

FI-3487: Fix response content types #616

Merged
merged 2 commits into from
Feb 14, 2025
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
4 changes: 3 additions & 1 deletion lib/inferno/apps/web/controllers/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def self.inherited(subclass)
# Hanami Controller 2.0.0 removes the ability to set a default
# Content-Type response header, so set it manually if it hasn't been
# set.
subclass.after { |_req, res| res.format = :json if res.format == :all && res.body&.first&.first == '{' }
subclass.after do |_req, res|
res.format = :json if res.format == :all
end
end

def self.resource_name
Expand Down
18 changes: 12 additions & 6 deletions lib/inferno/apps/web/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

module Inferno
module Web
client_page = ERB.new(File.read(File.join(Inferno::Application.root, 'lib', 'inferno', 'apps', 'web',
'index.html.erb'))).result
client_page = ERB.new(
File.read(
File.join(Inferno::Application.root, 'lib', 'inferno', 'apps', 'web', 'index.html.erb')
)
).result
CLIENT_PAGE_RESPONSE = ->(_env) { [200, { 'Content-Type' => 'text/html' }, [client_page]] }

base_path = Application['base_path']&.delete_prefix('/')

Expand Down Expand Up @@ -47,12 +51,14 @@ module Web

get '/requests/:id', to: Inferno::Web::Controllers::Requests::Show, as: :requests_show

get '/version', to: ->(_env) { [200, {}, [{ 'version' => Inferno::VERSION.to_s }.to_json]] }, as: :version
get '/version', to: lambda { |_env|
[200, { 'Content-Type' => 'application/json' }, [{ 'version' => Inferno::VERSION.to_s }.to_json]]
}, as: :version
end

# Should not need Content-Type header but GitHub Codespaces will not work without them.
# This could be investigated and likely removed if addressed properly elsewhere.
get '/', to: ->(_env) { [200, { 'Content-Type' => 'text/html' }, [client_page]] }
get '/', to: CLIENT_PAGE_RESPONSE
get '/jwks.json', to: lambda { |_env|
[200, { 'Content-Type' => 'application/json' }, [Inferno::JWKS.jwks_json]]
}, as: :jwks
Expand All @@ -70,7 +76,7 @@ module Web

Inferno::Repositories::TestSuites.all.map { |suite| "/#{suite.id}" }.each do |suite_path|
Application['logger'].info("Registering suite route: #{suite_path}")
get suite_path, to: ->(_env) { [200, {}, [client_page]] }
get suite_path, to: CLIENT_PAGE_RESPONSE
end

get '/test_sessions/:id', to: Inferno::Web::Controllers::TestSessions::ClientShow, as: :client_session_show
Expand All @@ -83,7 +89,7 @@ module Web
if base_path.present?
Hanami::Router.new do
scope("#{base_path}/") do
get '/', to: ->(_env) { [200, { 'Content-Type' => 'text/html' }, [client_page]] }
get '/', to: CLIENT_PAGE_RESPONSE
end
scope(base_path, &route_block)
end
Expand Down