lib/nyara/controller.rb in nyara-0.0.1.pre.2 vs lib/nyara/controller.rb in nyara-0.0.1.pre.3
- old
+ new
@@ -181,11 +181,11 @@
end
def add_header_line h
raise 'can not modify sent header' if request.response_header.frozen?
h = h.sub /(?<![\r\n])\z/, "\r\n"
- request.response_header_extra_lines << s
+ request.response_header_extra_lines << h
end
# todo args helper
def param
@@ -196,19 +196,38 @@
def cookie
request.cookie
end
alias cookies cookie
- def set_cookie k, v=nil, opts
+ # Set cookie, if expires is +Time.now+, will remove the cookie entry
+ #
+ # :call-seq:
+ #
+ # set_cookie 'JSESSIONID', 'not-exist'
+ # set_cookie 'key-without-value'
+ #
+ # +opt: default_value+ are:
+ #
+ # expires: nil
+ # max_age: nil
+ # domain: nil
+ # path: nil
+ # secure: nil
+ # httponly: true
+ #
+ def set_cookie name, value=nil, opts={}
+ if value.is_a?(Hash)
+ raise ArgumentError, 'hash not allowed in cookie value, did you mean to use it as options?'
+ end
# todo default domain ?
opts = Hash[opts.map{|k,v| [k.to_sym,v]}]
- Cookie.output_set_cookie response.response_header_extra_lines, k, v, opts
+ Cookie.add_set_cookie request.response_header_extra_lines, name, value, opts
end
- def delete_cookie k
+ def delete_cookie name
# todo domain ? path ?
- set_cookie k, expires: Time.now, max_age: 0
+ set_cookie name, nil, expires: Time.now, max_age: 0
end
def clear_cookie
cookie.each do |k, _|
delete_cookie k
@@ -236,11 +255,11 @@
# Send respones first line and header data, and freeze +header+ to forbid further changes
def send_header template_deduced_content_type=nil
r = request
header = r.response_header
- Ext.send_data r, HTTP_STATUS_FIRST_LINES[r.status]
+ Ext.request_send_data r, HTTP_STATUS_FIRST_LINES[r.status]
header.aset_content_type \
r.response_content_type ||
header.aref_content_type ||
(r.accept and MIME_TYPES[r.accept]) ||
@@ -252,29 +271,29 @@
data = header.map do |k, v|
"#{k}: #{v}\r\n"
end
data.concat r.response_header_extra_lines
data << "\r\n"
- Ext.send_data r, data.join
+ Ext.request_send_data r, data.join
# forbid further modification
header.freeze
end
# Send raw data, that is, not wrapped in chunked encoding<br>
# NOTE: often you should call send_header before doing this.
def send_data data
- Ext.send_data request, data.to_s
+ Ext.request_send_data request, data.to_s
end
# Send a data chunk, it can send_header first if header is not sent.
- #
+ #
# :call-seq:
#
# send_chunk 'hello world!'
def send_chunk data
send_header unless request.response_header.frozen?
- Ext.send_chunk request, data.to_s
+ Ext.request_send_chunk request, data.to_s
end
alias send_string send_chunk
# Send file
def send_file file