Permalink
Browse files

Merge pull request #224 from kou/parse-accept-encoding-loosely

parse Accept-Encoding header loosely.
  • Loading branch information...
raggi committed Sep 7, 2011
2 parents 92e5aef + 9483488 commit c3a1348612d39bf4da1c48a2f781ec49af293f16
Showing with 8 additions and 8 deletions.
  1. +6 −7 lib/rack/request.rb
  2. +2 −1 test/spec_request.rb
View
@@ -278,14 +278,13 @@ def fullpath
end
def accept_encoding
- @env["HTTP_ACCEPT_ENCODING"].to_s.split(/,\s*/).map do |part|
- m = /^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$/.match(part) # From WEBrick
-
- if m
- [m[1], (m[2] || 1.0).to_f]
- else
- raise "Invalid value for Accept-Encoding: #{part.inspect}"
+ @env["HTTP_ACCEPT_ENCODING"].to_s.split(/\s*,\s*/).map do |part|
+ encoding, parameters = part.split(/\s*;\s*/, 2)
+ quality = 1.0
+ if parameters and /\Aq=([\d.]+)/ =~ parameters
+ quality = $1.to_f
end
+ [encoding, quality]
end
end
View
@@ -748,7 +748,8 @@
parser.call("compress;q=0.5, gzip;q=1.0").should.equal([["compress", 0.5], ["gzip", 1.0]])
parser.call("gzip;q=1.0, identity; q=0.5, *;q=0").should.equal([["gzip", 1.0], ["identity", 0.5], ["*", 0] ])
- lambda { parser.call("gzip ; q=1.0") }.should.raise(RuntimeError)
+ parser.call("gzip ; q=0.9").should.equal([["gzip", 0.9]])
+ parser.call("gzip ; deflate").should.equal([["gzip", 1.0]])
end
should 'provide ip information' do

0 comments on commit c3a1348

Please sign in to comment.