./lib/lux/response/response.rb in lux-fw-0.2.1 vs ./lib/lux/response/response.rb in lux-fw-0.2.3
- old
+ new
@@ -163,38 +163,27 @@
end
end
def write_response_header
domain =
- if cookie_domain
- cookie_domain
- elsif cookie_multidomain && current.domain.index('.')
+ if cookie_multidomain && current.domain.index('.')
".#{current.domain}"
else
- current.request.host
+ cookie_domain || current.request.host
end
# cache-control
@headers['cache-control'] ||= Proc.new do
- cc = ['max-age=%d' % max_age]
-
- if max_age > 0
- cc.push 'public, no-cache'
- else
- cc.push 'private, must-revalidate'
- end
-
+ cc = ['max-age=%d' % max_age]
+ cc.push max_age > 0 ? 'public, no-cache' : 'private, must-revalidate'
cc.join(', ')
end.call
current.session[:lux_flash] = flash.to_h
# dont annd cookies to public pages (images, etc..)
- add_cookies = true
- add_cookies = false if @headers['cache-control'].index('public')
-
- if add_cookies
+ unless @headers['cache-control'].index('public')
encrypted = Crypt.encrypt(current.session.to_json)
if current.cookies[Lux.config.session_cookie_name] != encrypted
@headers['set-cookie'] = "#{Lux.config.session_cookie_name}=#{encrypted}; Expires=#{(Time.now+1.month).utc}; Path=/; Domain=#{domain};"
end
@@ -206,11 +195,11 @@
@headers['content-type'] ||= "#{@content_type}; charset=utf-8"
@headers['content-length'] = @body.bytesize
# if "no-store" is present then HTTP_IF_NONE_MATCH is not sent from browser
end
- def write_response
+ def render
write_response_body
write_response_header
@status ||= 200
Lux.log " #{@status}, #{@headers['x-lux-speed']}"
@@ -220,18 +209,8 @@
puts @status == 404 ? 'without a match'.red : 'with a match'.green
exit
end
[@status, @headers.to_h, [@body]]
- end
-
- def render
- Lux.log "\n#{current.request.request_method.white} #{Lux.current.request.path.white}"
-
- Lux::Config.live_require_check! if Lux.config(:auto_code_reload)
-
- Lux::Application.new.main
-
- write_response
end
end