Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

parse Accept-Encoding header loosely. #224

Merged
merged 1 commit into from

2 participants

@kou

After this commit, Rack::Request#accept_encoding doesn't
raise an exception for invalid Accept-Encoding value.

If Rack::Request#accept_encoding may raise an exception,
Rack::Middleware::Deflater may also raise an exception.
Because Rack::Middleware::Deflater dosn't rescue an
exception from Rack::Request#accept_encoding.

On the exception case, it seems that either returning "400
Bad Request" or just ignoring invalid value is better
behavior. This patch uses the latter solution.

@kou kou parse Accept-Encoding header loosely.
After this commit, Rack::Request#accept_encoding doesn't
raise an exception for invalid Accept-Encoding value.

If Rack::Request#accept_encoding may raise an exception,
Rack::Middleware::Deflater may also raise an exception.
Because Rack::Middleware::Deflater dosn't rescue an
exception from Rack::Request#accept_encoding.

On the exception case, it seems that either returning "400
Bad Request" or just ignoring invalid value is better
behavior. This patch uses the latter solution.
9483488
@raggi raggi merged commit c3a1348 into rack:master
@raggi
Owner

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 21, 2011
  1. @kou

    parse Accept-Encoding header loosely.

    kou authored
    After this commit, Rack::Request#accept_encoding doesn't
    raise an exception for invalid Accept-Encoding value.
    
    If Rack::Request#accept_encoding may raise an exception,
    Rack::Middleware::Deflater may also raise an exception.
    Because Rack::Middleware::Deflater dosn't rescue an
    exception from Rack::Request#accept_encoding.
    
    On the exception case, it seems that either returning "400
    Bad Request" or just ignoring invalid value is better
    behavior. This patch uses the latter solution.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 8 deletions.
  1. +6 −7 lib/rack/request.rb
  2. +2 −1  test/spec_request.rb
View
13 lib/rack/request.rb
@@ -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
3  test/spec_request.rb
@@ -735,7 +735,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
Something went wrong with that request. Please try again.