lib/roda/plugins/sinatra_helpers.rb in roda-3.69.0 vs lib/roda/plugins/sinatra_helpers.rb in roda-3.70.0
- old
+ new
@@ -325,11 +325,11 @@
# Use the contents of the file at +path+ as the response body. See plugin documentation for options.
def send_file(path, opts = OPTS)
res = response
headers = res.headers
- if opts[:type] || !headers["Content-Type"]
+ if opts[:type] || !headers[RodaResponseHeaders::CONTENT_TYPE]
res.content_type(opts[:type] || ::File.extname(path), :default => 'application/octet-stream')
end
disposition = opts[:disposition]
filename = opts[:filename]
@@ -350,11 +350,11 @@
file.path = path
file.serving(@env)
end
res.status = opts[:status] || s
- headers.delete("Content-Length")
+ headers.delete(RodaResponseHeaders::CONTENT_LENGTH)
headers.replace(h.merge!(headers))
res.body = b
halt
rescue Errno::ENOENT
@@ -405,11 +405,11 @@
@body = DelayedBody.new{body}
end
# If the body is a DelayedBody, set the appropriate length for it.
def finish
- @length = @body.length if @body.is_a?(DelayedBody) && !@headers["Content-Length"]
+ @length = @body.length if @body.is_a?(DelayedBody) && !@headers[RodaResponseHeaders::CONTENT_LENGTH]
super
end
# Set multiple response headers with Hash, or return the headers if no
# argument is given.
@@ -422,11 +422,11 @@
roda_class.mime_type(type)
end
# Set the Content-Type of the response body given a media type or file
# extension. See plugin documentation for options.
- def content_type(type = nil || (return @headers["Content-Type"]), opts = OPTS)
+ def content_type(type = nil || (return @headers[RodaResponseHeaders::CONTENT_TYPE]), opts = OPTS)
unless (mime_type = mime_type(type) || opts[:default])
raise RodaError, "Unknown media type: #{type}"
end
unless opts.empty?
@@ -435,11 +435,11 @@
val = val.inspect if val =~ /[";,]/
mime_type += "#{mime_type.include?(';') ? ', ' : ';'}#{key}=#{val}"
end
end
- @headers["Content-Type"] = mime_type
+ @headers[RodaResponseHeaders::CONTENT_TYPE] = mime_type
end
# Set the Content-Disposition to "attachment" with the specified filename,
# instructing the user agents to prompt to save.
def attachment(filename = nil, disposition='attachment')
@@ -461,17 +461,17 @@
end
encoded_params = "; filename*=#{encoding.to_s}''#{encoded_filename}"
end
- unless @headers["Content-Type"]
+ unless @headers[RodaResponseHeaders::CONTENT_TYPE]
ext = File.extname(filename)
unless ext.empty?
content_type(ext)
end
end
end
- @headers["Content-Disposition"] = "#{disposition}#{params}#{encoded_params}"
+ @headers[RodaResponseHeaders::CONTENT_DISPOSITION] = "#{disposition}#{params}#{encoded_params}"
end
# Whether or not the status is set to 1xx. Returns nil if status not yet set.
def informational?
@status.between?(100, 199) if @status