Skip to content

Commit e2d9baa

Browse files
committed
use Rack::Utils.best_q_match in ErrorApp if available, also accepts_html? is private API
1 parent cd91e74 commit e2d9baa

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/main/ruby/jruby/rack/error_app.rb

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,6 @@ def serve(code, path, env)
8383

8484
protected
8585

86-
def accept_html?(env)
87-
http_accept = env['HTTP_ACCEPT'].to_s
88-
if ! http_accept.empty? # NOTE: some really stupid matching for now :
89-
!! ( http_accept.index('text/html') || http_accept.index('*/*') )
90-
else
91-
nil
92-
end
93-
end
94-
9586
def map_error_code(exc)
9687
cause = exc.respond_to?(:cause) ? exc.cause : nil
9788
if UNAVAILABLE_EXCEPTIONS.any? { |type| exc.kind_of?(type) }
@@ -150,7 +141,28 @@ def expand_path(path, root = self.root)
150141
begin
151142
require 'rack/utils'
152143
require 'rack/mime'
153-
rescue LoadError
144+
rescue LoadError; end
145+
146+
if defined? Rack::Utils.best_q_match
147+
148+
def accepts_html?(env)
149+
Rack::Utils.best_q_match(env['HTTP_ACCEPT'], %w[text/html])
150+
rescue
151+
http_accept?(env, 'text/html')
152+
end
153+
154+
else
155+
156+
def accepts_html?(env)
157+
http_accept?(env, 'text/html') || http_accept?(env, '*/*')
158+
end
159+
160+
end
161+
alias accept_html? accepts_html? # JRuby-Rack 1.1 compatibility
162+
163+
def http_accept?(env, mime)
164+
http_accept = env['HTTP_ACCEPT'].to_s
165+
http_accept.empty? ? nil : !! http_accept.index(mime)
154166
end
155167

156168
end

0 commit comments

Comments
 (0)