File tree 3 files changed +9
-11
lines changed
3 files changed +9
-11
lines changed Original file line number Diff line number Diff line change
1
+ # Decides whether this is a browser request or a request for the API
1
2
module Rack
2
3
module PactBroker
3
4
class AcceptsHtmlFilter
4
-
5
5
def initialize app
6
6
@app = app
7
7
end
8
8
9
9
def call env
10
- if accepts_html_and_not_json_or_csv env
10
+ if accepts_web_content_types_and_not_api_media env
11
11
@app . call ( env )
12
12
else
13
13
[ 404 , { } , [ ] ]
14
14
end
15
15
end
16
16
17
- def accepts_html_and_not_json_or_csv env
17
+ def accepts_web_content_types_and_not_api_media env
18
18
accept = env [ 'HTTP_ACCEPT' ] || ''
19
- accepts_html ( accept ) && !accepts_json_or_csv ( accept )
19
+ accepts_web_content_types ( accept ) && !accepts_api_content_types ( accept )
20
20
end
21
21
22
- def accepts_html ( accept )
23
- accept . include? ( "html" )
22
+ def accepts_web_content_types ( accept )
23
+ accept . include? ( "*/*" ) || accept . include? ( " html" ) || accept . include? ( "text/css" ) || accept . include? ( "text/javascript ")
24
24
end
25
25
26
- def accepts_json_or_csv accept
26
+ def accepts_api_content_types accept
27
27
accept . include? ( "json" ) || accept . include? ( "csv" )
28
28
end
29
29
end
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ def initialize app
9
9
def call env
10
10
response = @app . call ( env )
11
11
12
- if response . first == 404 && response [ 1 ] [ 'Content-Type' ] == 'text/html' && !( env [ 'HTTP_ACCEPT' ] =~ /html/ )
12
+ if response . first == 404 && response [ 1 ] [ 'Content-Type' ] == 'text/html' && !( env [ 'HTTP_ACCEPT' ] =~ /html|javascript|css / )
13
13
[ 404 , { 'Content-Type' => 'application/hal+json' } , [ ] ]
14
14
else
15
15
response
Original file line number Diff line number Diff line change @@ -11,9 +11,7 @@ class ConvertFileExtensionToAcceptHeader
11
11
".csv" => "text/csv" ,
12
12
".svg" => "image/svg+xml" ,
13
13
".json" => "application/hal+json" ,
14
- ".yaml" => "application/yaml" ,
15
- ".css" => "text/css" ,
16
- ".js" => "text/javascript"
14
+ ".yaml" => "application/yaml"
17
15
}
18
16
19
17
def initialize app
You can’t perform that action at this time.
0 commit comments