From 1c8e199f48bbd4e8de77a5623ffdd1f079b65a0c Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 10 Sep 2018 11:26:16 +1000 Subject: [PATCH] feat: treat .yaml requests as having header Accept: application/x-yaml --- .../convert_file_extension_to_accept_header.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/rack/pact_broker/convert_file_extension_to_accept_header.rb b/lib/rack/pact_broker/convert_file_extension_to_accept_header.rb index c6a34ea62..37defd090 100644 --- a/lib/rack/pact_broker/convert_file_extension_to_accept_header.rb +++ b/lib/rack/pact_broker/convert_file_extension_to_accept_header.rb @@ -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 @@ -37,8 +41,6 @@ def set_accept_header_and_path_info env, file_extension "HTTP_ACCEPT" => EXTENSIONS[file_extension] ) end - end - end end