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

extract ETAG_KINDS to a constant

also use string interpolation instead of  addition
This commit is contained in:
Vipul A M 2013-07-21 01:47:09 +05:30
parent 91127334a9
commit 55d1de945e

View file

@ -513,6 +513,7 @@ module Sinatra
rescue ArgumentError rescue ArgumentError
end end
ETAG_KINDS = [:strong, :weak]
# Set the response entity tag (HTTP 'ETag' header) and halt if conditional # Set the response entity tag (HTTP 'ETag' header) and halt if conditional
# GET matches. The +value+ argument is an identifier that uniquely # GET matches. The +value+ argument is an identifier that uniquely
# identifies the current version of the resource. The +kind+ argument # identifies the current version of the resource. The +kind+ argument
@ -528,12 +529,12 @@ module Sinatra
kind = options[:kind] || :strong kind = options[:kind] || :strong
new_resource = options.fetch(:new_resource) { request.post? } new_resource = options.fetch(:new_resource) { request.post? }
unless [:strong, :weak].include?(kind) unless ETAG_KINDS.include?(kind)
raise ArgumentError, ":strong or :weak expected" raise ArgumentError, ":strong or :weak expected"
end end
value = '"%s"' % value value = '"%s"' % value
value = 'W/' + value if kind == :weak value = "W/#{value}" if kind == :weak
response['ETag'] = value response['ETag'] = value
if success? or status == 304 if success? or status == 304