diff --git a/lib/rack/pact_broker/accepts_html_filter.rb b/lib/rack/pact_broker/accepts_html_filter.rb
index 29d9b5a21..d0ff21e8c 100644
--- a/lib/rack/pact_broker/accepts_html_filter.rb
+++ b/lib/rack/pact_broker/accepts_html_filter.rb
@@ -1,29 +1,29 @@
+# Decides whether this is a browser request or a request for the API
module Rack
module PactBroker
class AcceptsHtmlFilter
-
def initialize app
@app = app
end
def call env
- if accepts_html_and_not_json_or_csv env
+ if accepts_web_content_types_and_not_api_media env
@app.call(env)
else
[404, {},[]]
end
end
- def accepts_html_and_not_json_or_csv env
+ def accepts_web_content_types_and_not_api_media env
accept = env['HTTP_ACCEPT'] || ''
- accepts_html(accept) && !accepts_json_or_csv(accept)
+ accepts_web_content_types(accept) && !accepts_api_content_types(accept)
end
- def accepts_html(accept)
- accept.include?("html")
+ def accepts_web_content_types(accept)
+ accept.include?("*/*") || accept.include?("html") || accept.include?("text/css") || accept.include?("text/javascript")
end
- def accepts_json_or_csv accept
+ def accepts_api_content_types accept
accept.include?("json") || accept.include?("csv")
end
end
diff --git a/lib/rack/pact_broker/convert_404_to_hal.rb b/lib/rack/pact_broker/convert_404_to_hal.rb
index 098547516..13e6456e2 100644
--- a/lib/rack/pact_broker/convert_404_to_hal.rb
+++ b/lib/rack/pact_broker/convert_404_to_hal.rb
@@ -9,7 +9,7 @@ def initialize app
def call env
response = @app.call(env)
- if response.first == 404 && response[1]['Content-Type'] == 'text/html' && !(env['HTTP_ACCEPT'] =~ /html/)
+ if response.first == 404 && response[1]['Content-Type'] == 'text/html' && !(env['HTTP_ACCEPT'] =~ /html|javascript|css/)
[404, { 'Content-Type' => 'application/hal+json'},[]]
else
response
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 f47a3d373..f2f4b1585 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
@@ -11,9 +11,7 @@ class ConvertFileExtensionToAcceptHeader
".csv" => "text/csv",
".svg" => "image/svg+xml",
".json" => "application/hal+json",
- ".yaml" => "application/yaml",
- ".css" => "text/css",
- ".js" => "text/javascript"
+ ".yaml" => "application/yaml"
}
def initialize app