Skip to content

Commit 1c8e199

Browse files
committed
feat: treat .yaml requests as having header Accept: application/x-yaml
1 parent 150858a commit 1c8e199

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/rack/pact_broker/convert_file_extension_to_accept_header.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
module Rack
22
module PactBroker
3-
43
# If the HTML and the CSV group resources are both requested by the browser,
54
# Chrome gets confused by the content types, and when you click back, it tries to load the CSV
65
# instead of the HTML page. So we have to give the CSV resource a different URL (.csv)
76

87
class ConvertFileExtensionToAcceptHeader
98

10-
EXTENSIONS = {".csv" => "text/csv", ".svg" => "image/svg+xml", ".json" => "application/hal+json"}
11-
EXTENSION_REGEXP = /\.\w+$/
9+
EXTENSION_REGEXP = /\.\w+$/.freeze
10+
EXTENSIONS = {
11+
".csv" => "text/csv",
12+
".svg" => "image/svg+xml",
13+
".json" => "application/hal+json",
14+
".yaml" => "application/x-yaml"
15+
}
1216

1317
def initialize app
1418
@app = app
@@ -37,8 +41,6 @@ def set_accept_header_and_path_info env, file_extension
3741
"HTTP_ACCEPT" => EXTENSIONS[file_extension]
3842
)
3943
end
40-
4144
end
42-
4345
end
4446
end

0 commit comments

Comments
 (0)