Added put_expires_string (s: STRING) and put_expires_date (dt: DATE_TIME)
Better implementation for WSF_FILE_RESPONSE (added last modified, and other caching related info)
This commit is contained in:
@@ -390,23 +390,33 @@ feature -- Date
|
|||||||
put_utc_date (create {DATE_TIME}.make_now_utc)
|
put_utc_date (create {DATE_TIME}.make_now_utc)
|
||||||
end
|
end
|
||||||
|
|
||||||
put_utc_date (dt: DATE_TIME)
|
put_utc_date (a_utc_date: DATE_TIME)
|
||||||
-- Put UTC date time `dt' with "Date" header
|
-- Put UTC date time `dt' with "Date" header
|
||||||
do
|
do
|
||||||
put_date (date_to_rfc1123_http_date_format (dt))
|
put_date (date_to_rfc1123_http_date_format (a_utc_date))
|
||||||
end
|
end
|
||||||
|
|
||||||
put_last_modified (dt: DATE_TIME)
|
put_last_modified (a_utc_date: DATE_TIME)
|
||||||
-- Put UTC date time `dt' with "Date" header
|
-- Put UTC date time `dt' with "Date" header
|
||||||
do
|
do
|
||||||
put_header_key_value ({HTTP_HEADER_NAMES}.header_last_modified, date_to_rfc1123_http_date_format (dt))
|
put_header_key_value ({HTTP_HEADER_NAMES}.header_last_modified, date_to_rfc1123_http_date_format (a_utc_date))
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Others
|
feature -- Others
|
||||||
|
|
||||||
put_expires (n: INTEGER)
|
put_expires (sec: INTEGER)
|
||||||
do
|
do
|
||||||
put_header_key_value ("Expires", n.out)
|
put_expires_string (sec.out)
|
||||||
|
end
|
||||||
|
|
||||||
|
put_expires_string (s: STRING)
|
||||||
|
do
|
||||||
|
put_header_key_value ("Expires", s)
|
||||||
|
end
|
||||||
|
|
||||||
|
put_expires_date (a_utc_date: DATE_TIME)
|
||||||
|
do
|
||||||
|
put_header_key_value ("Expires", date_to_rfc1123_http_date_format (a_utc_date))
|
||||||
end
|
end
|
||||||
|
|
||||||
put_cache_control (s: READABLE_STRING_8)
|
put_cache_control (s: READABLE_STRING_8)
|
||||||
|
|||||||
@@ -42,18 +42,23 @@ feature {NONE} -- Initialization
|
|||||||
local
|
local
|
||||||
h: like header
|
h: like header
|
||||||
do
|
do
|
||||||
|
get_file_exists
|
||||||
create h.make
|
create h.make
|
||||||
header := h
|
header := h
|
||||||
|
|
||||||
h.put_content_type (content_type)
|
h.put_content_type (content_type)
|
||||||
if attached file_last_modified as dt then
|
|
||||||
h.put_last_modified (dt)
|
if file_exists then
|
||||||
end
|
if attached file_last_modified as dt then
|
||||||
get_file_size
|
h.put_last_modified (dt)
|
||||||
if file_size = 0 then
|
end
|
||||||
set_status_code ({HTTP_STATUS_CODE}.not_found)
|
get_file_size
|
||||||
|
if file_size = 0 then
|
||||||
|
set_status_code ({HTTP_STATUS_CODE}.not_found)
|
||||||
|
else
|
||||||
|
set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
set_status_code ({HTTP_STATUS_CODE}.ok)
|
set_status_code ({HTTP_STATUS_CODE}.not_found)
|
||||||
end
|
end
|
||||||
update_content_length
|
update_content_length
|
||||||
end
|
end
|
||||||
@@ -62,12 +67,16 @@ feature {NONE} -- Initialization
|
|||||||
local
|
local
|
||||||
n: INTEGER
|
n: INTEGER
|
||||||
do
|
do
|
||||||
n := file_size
|
if file_exists then
|
||||||
if attached head as h then
|
n := file_size
|
||||||
n := n + h.count
|
if attached head as h then
|
||||||
end
|
n := n + h.count
|
||||||
if attached bottom as b then
|
end
|
||||||
n := n + b.count
|
if attached bottom as b then
|
||||||
|
n := n + b.count
|
||||||
|
end
|
||||||
|
else
|
||||||
|
n := 0
|
||||||
end
|
end
|
||||||
content_length := n
|
content_length := n
|
||||||
header.put_content_length (n)
|
header.put_content_length (n)
|
||||||
@@ -75,9 +84,14 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
feature -- Element change
|
feature -- Element change
|
||||||
|
|
||||||
set_expires (t: INTEGER)
|
set_expires_in_seconds (sec: INTEGER)
|
||||||
do
|
do
|
||||||
header.put_expires (t)
|
set_expires (sec.out)
|
||||||
|
end
|
||||||
|
|
||||||
|
set_expires (s: STRING)
|
||||||
|
do
|
||||||
|
header.put_expires_string (s)
|
||||||
end
|
end
|
||||||
|
|
||||||
set_no_cache
|
set_no_cache
|
||||||
@@ -104,6 +118,9 @@ feature -- Access
|
|||||||
|
|
||||||
file_name: READABLE_STRING_8
|
file_name: READABLE_STRING_8
|
||||||
|
|
||||||
|
file_exists: BOOLEAN
|
||||||
|
-- File exists?
|
||||||
|
|
||||||
file_size: INTEGER
|
file_size: INTEGER
|
||||||
-- Size of file named `file_name'
|
-- Size of file named `file_name'
|
||||||
|
|
||||||
@@ -157,42 +174,54 @@ feature {WSF_RESPONSE} -- Output
|
|||||||
s: detachable READABLE_STRING_8
|
s: detachable READABLE_STRING_8
|
||||||
do
|
do
|
||||||
res.set_status_code (status_code)
|
res.set_status_code (status_code)
|
||||||
res.put_header_text (header.string)
|
if status_code = {HTTP_STATUS_CODE}.not_found then
|
||||||
s := head
|
else
|
||||||
if s /= Void then
|
res.put_header_text (header.string)
|
||||||
res.put_string (s)
|
s := head
|
||||||
end
|
if s /= Void then
|
||||||
if not answer_head_request_method then
|
res.put_string (s)
|
||||||
send_file_content_to (file_name, res)
|
end
|
||||||
end
|
if not answer_head_request_method then
|
||||||
s := bottom
|
send_file_content_to (file_name, res)
|
||||||
if s /= Void then
|
end
|
||||||
res.put_string (s)
|
s := bottom
|
||||||
|
if s /= Void then
|
||||||
|
res.put_string (s)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation: file system helper
|
feature {NONE} -- Implementation: file system helper
|
||||||
|
|
||||||
get_file_size
|
get_file_exists
|
||||||
-- Get `file_size' from file named `file_name'
|
-- Get `file_exists'
|
||||||
local
|
local
|
||||||
f: RAW_FILE
|
f: RAW_FILE
|
||||||
do
|
do
|
||||||
create f.make (file_name)
|
create f.make (file_name)
|
||||||
if f.exists then
|
file_exists := f.exists
|
||||||
file_size := f.count
|
end
|
||||||
end
|
|
||||||
|
get_file_size
|
||||||
|
-- Get `file_size' from file named `file_name'
|
||||||
|
require
|
||||||
|
file_exists: file_exists
|
||||||
|
local
|
||||||
|
f: RAW_FILE
|
||||||
|
do
|
||||||
|
create f.make (file_name)
|
||||||
|
file_size := f.count
|
||||||
end
|
end
|
||||||
|
|
||||||
file_last_modified: detachable DATE_TIME
|
file_last_modified: detachable DATE_TIME
|
||||||
-- Get `file_size' from file named `file_name'
|
-- Get `file_size' from file named `file_name'
|
||||||
|
require
|
||||||
|
file_exists: file_exists
|
||||||
local
|
local
|
||||||
f: RAW_FILE
|
f: RAW_FILE
|
||||||
do
|
do
|
||||||
create f.make (file_name)
|
create f.make (file_name)
|
||||||
if f.exists then
|
create Result.make_from_epoch (f.change_date)
|
||||||
create Result.make_from_epoch (f.change_date)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
file_extension (fn: STRING): STRING
|
file_extension (fn: STRING): STRING
|
||||||
@@ -231,11 +260,12 @@ feature {NONE} -- Implementation: output
|
|||||||
require
|
require
|
||||||
string_not_empty: not fn.is_empty
|
string_not_empty: not fn.is_empty
|
||||||
is_readable: (create {RAW_FILE}.make (fn)).is_readable
|
is_readable: (create {RAW_FILE}.make (fn)).is_readable
|
||||||
|
file_exists: file_exists
|
||||||
local
|
local
|
||||||
f: RAW_FILE
|
f: RAW_FILE
|
||||||
do
|
do
|
||||||
create f.make (fn)
|
create f.make (fn)
|
||||||
check f.exists and then f.is_readable end
|
check f.is_readable end
|
||||||
|
|
||||||
f.open_read
|
f.open_read
|
||||||
from
|
from
|
||||||
|
|||||||
Reference in New Issue
Block a user