Skip to content

Commit

Permalink
feat: treat .yaml requests as having header Accept: application/x-yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 10, 2018
1 parent 150858a commit 1c8e199
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/rack/pact_broker/convert_file_extension_to_accept_header.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
module Rack
module PactBroker

# 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)

class ConvertFileExtensionToAcceptHeader

EXTENSIONS = {".csv" => "text/csv", ".svg" => "image/svg+xml", ".json" => "application/hal+json"}
EXTENSION_REGEXP = /\.\w+$/
EXTENSION_REGEXP = /\.\w+$/.freeze
EXTENSIONS = {
".csv" => "text/csv",
".svg" => "image/svg+xml",
".json" => "application/hal+json",
".yaml" => "application/x-yaml"
}

def initialize app
@app = app
Expand Down Expand Up @@ -37,8 +41,6 @@ def set_accept_header_and_path_info env, file_extension
"HTTP_ACCEPT" => EXTENSIONS[file_extension]
)
end

end

end
end

0 comments on commit 1c8e199

Please sign in to comment.