class Rack::PactBroker::ConvertFileExtensionToAcceptHeader
If the HTML and the CSV group resources are both requested by the browser, Chrome gets confused by the content types, and when you click back, it tries to load the CSV instead of the HTML page. So we have to give the CSV resource a different URL (.csv) Update: this should be fixed by lib/rack/pact_broker/add_vary_header.rb, but may as well leave it now!
Constants
- EXTENSIONS
- EXTENSION_REGEXP
Public Class Methods
new(app)
click to toggle source
# File lib/rack/pact_broker/convert_file_extension_to_accept_header.rb, line 19 def initialize app @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/pact_broker/convert_file_extension_to_accept_header.rb, line 23 def call env file_extension = extension(env) if convert_to_accept_header? file_extension @app.call(set_accept_header_and_path_info(env, file_extension)) else @app.call(env) end end
convert_to_accept_header?(file_extension)
click to toggle source
# File lib/rack/pact_broker/convert_file_extension_to_accept_header.rb, line 32 def convert_to_accept_header? file_extension EXTENSIONS[file_extension] end
extension(env)
click to toggle source
# File lib/rack/pact_broker/convert_file_extension_to_accept_header.rb, line 36 def extension env env["PATH_INFO"] =~ EXTENSION_REGEXP && $~[0] end
set_accept_header_and_path_info(env, file_extension)
click to toggle source
# File lib/rack/pact_broker/convert_file_extension_to_accept_header.rb, line 40 def set_accept_header_and_path_info env, file_extension env.merge( "PATH_INFO" => env["PATH_INFO"].gsub(EXTENSION_REGEXP, ""), "HTTP_ACCEPT" => EXTENSIONS[file_extension] ) end