1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

fix HEADER_VALUE_WITH_PARAMS regex and added a test case for this regex.

This commit is contained in:
Patricio Mac Adden 2013-03-14 00:18:13 -03:00
parent 54d6ba06cc
commit 05c16d51d0
2 changed files with 11 additions and 1 deletions

View file

@ -17,7 +17,7 @@ module Sinatra
# http://rack.rubyforge.org/doc/classes/Rack/Request.html
class Request < Rack::Request
HEADER_PARAM = /\s*[\w.]+=(?:[\w.]+|"(?:[^"\\]|\\.)*")?\s*/
HEADER_VALUE_WITH_PARAMS = /(?:(?:\w+|\*)\/(?:\w+|\*))\s*(?:;#{HEADER_PARAM})*/
HEADER_VALUE_WITH_PARAMS = /(?:(?:\w+|\*)\/(?:\w+\-*\w+|\*))\s*(?:;#{HEADER_PARAM})*/
# Returns an array of acceptable media types for the response
def accept

View file

@ -776,6 +776,9 @@ class RoutingTest < Test::Unit::TestCase
get '/foo', :provides => :html do
env['HTTP_ACCEPT']
end
get '/stream', :provides => 'text/event-stream' do
env['HTTP_ACCEPT']
end
}
get '/', {}, { 'HTTP_ACCEPT' => 'application/xml' }
@ -792,6 +795,13 @@ class RoutingTest < Test::Unit::TestCase
get '/foo', {}, { 'HTTP_ACCEPT' => '' }
assert !ok?
get '/stream', {}, { 'HTTP_ACCEPT' => 'text/event-stream' }
assert ok?
assert_equal 'text/event-stream', body
get '/stream', {}, { 'HTTP_ACCEPT' => '' }
assert !ok?
end
it "filters by current Content-Type" do