lib/merb/mixins/controller_mixin.rb in merb-0.0.8 vs lib/merb/mixins/controller_mixin.rb in merb-0.0.9
- old
+ new
@@ -14,18 +14,12 @@
# pass in a path to a file and this will set the
# right headers and let mongrel do its thang and
# serve the static file directly.
def send_file(file, opts={})
opts.update(Merb::Const::DEFAULT_SEND_FILE_OPTIONS.merge(opts))
- [:type, :disposition].each do |arg|
- raise ArgumentError, ":#{arg} option required" if opts[arg].nil?
- end
-
disposition = opts[:disposition].dup || 'attachment'
-
disposition << %(; filename="#{opts[:filename] ? opts[:filename] : File.basename(file)}")
-
headers.update(
'Content-Type' => opts[:type].strip, # fixes a problem with extra '\r' with some browsers
'Content-Disposition' => disposition,
'Content-Transfer-Encoding' => 'binary',
'X-SENDFILE' => file
@@ -38,9 +32,21 @@
# http://wiki.codemongers.com/NginxXSendfile
def nginx_send_file(file)
headers['X-Accel-Redirect'] = file
return
end
+
+ # Sets a cookie to be included in the response.
+ def set_cookie(name, value, expires)
+ (headers['Set-Cookie'] ||='') <<
+ (Merb::Const::SET_COOKIE % [name.to_s, escape(value.to_s), expires.rfc2822])
+ end
+
+ # Marks a cookie as deleted. The cookie is given an expires stamp in
+ # the past.
+ def delete_cookie(name)
+ set_cookie(name, nil, Merb::Const::COOKIE_EXPIRED_TIME)
+ end
# parses a query string or the payload of a POST
# request into the params hash. So for example:
# /foo?bar=nik&post[title]=heya&post[body]=whatever
# parses into:
\ No newline at end of file