Fixed expiration, and cache-control: max-age implementation.

Also use `FILE.date` instead of `FILE.change_date` (`change_date` is the date of the last status change, quite often same as creation date, while `date` is the last modification date).
This commit is contained in:
2016-10-24 12:51:21 +02:00
parent 885195dbaa
commit ac908e4efd
3 changed files with 59 additions and 32 deletions

View File

@@ -1,8 +1,7 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
description: "Response to send a file back to the client"
date: "$Date$"
revision: "$Revision$"
class
WSF_FILE_RESPONSE
@@ -105,22 +104,46 @@ feature {NONE} -- Initialization
feature -- Element change
set_expires_in_seconds (sec: INTEGER)
set_max_age (sec: INTEGER)
do
set_expires (sec.out)
header.put_cache_control ("max-age=" + sec.out)
end
set_public_max_age (sec: INTEGER)
do
header.put_cache_control ("public, max-age=" + sec.out)
end
set_private_max_age (sec: INTEGER)
do
header.put_cache_control ("private, max-age=" + sec.out)
end
set_expires_in_seconds (sec: INTEGER)
-- Set Expires and Cache-control: max-age... to value related `sec' seconds.
do
header.put_expires (sec)
end
set_expires (s: STRING)
-- Set Expires header value to `s'.
do
header.put_expires_string (s)
end
set_expires_date (dt: DATE_TIME)
-- Set Expires header value to date time `dt'.
do
header.put_expires_date (dt)
end
set_no_cache
local
h: like header
do
h := header
h.put_expires (0)
h.put_cache_control ("max-age=0")
h.put_cache_control ("no-cache, must-revalidate")
h.put_pragma_no_cache
end
@@ -250,7 +273,7 @@ feature {NONE} -- Implementation: file system helper
f: RAW_FILE
do
create f.make_with_path (file_path)
create Result.make_from_epoch (f.change_date)
create Result.make_from_epoch (f.date)
end
file_extension (fn: PATH): STRING_32
@@ -293,19 +316,11 @@ feature {NONE} -- Implementation: output
create f.make_with_path (fn)
check f.is_readable end
f.open_read
from
until
f.exhausted
loop
f.read_stream (4_096)
res.put_string (f.last_string)
end
f.close
res.put_file_content (f, 0, f.count)
end
note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software