Merge remote-tracking branch 'jocelyn/flexible_response' into cors

Conflicts:
	examples/filter/filter-safe.ecf
	examples/filter/src/filter_server.e
	library/network/protocol/http/src/http_header.e
	library/server/wsf/src/wsf_response.e
This commit is contained in:
Olivier Ligot
2013-03-15 13:33:13 +01:00
370 changed files with 9238 additions and 35495 deletions

View File

@@ -12,6 +12,10 @@
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<cluster name="src" location=".\" recursive="true"/>
<cluster name="src" location=".\" recursive="true">
<file_rule>
<exclude>/tests$</exclude>
</file_rule>
</cluster>
</target>
</system>

View File

@@ -12,7 +12,11 @@
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
<cluster name="src" location=".\" recursive="true"/>
<cluster name="src" location=".\" recursive="true">
<file_rule>
<exclude>/tests$</exclude>
</file_rule>
</cluster>
</target>
</system>

View File

@@ -0,0 +1,831 @@
note
description: "[
Summary description for {HTTP_DATE}.
HTTP-date = rfc1123-date | rfc850-date | asctime-date
rfc1123-date = wkday "," SP date1 SP time SP "GMT"
rfc850-date = weekday "," SP date2 SP time SP "GMT"
asctime-date = wkday SP date3 SP time SP 4DIGIT
date1 = 2DIGIT SP month SP 4DIGIT
; day month year (e.g., 02 Jun 1982)
date2 = 2DIGIT "-" month "-" 2DIGIT
; day-month-year (e.g., 02-Jun-82)
date3 = month SP ( 2DIGIT | ( SP 1DIGIT ))
; month day (e.g., Jun 2)
time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
; 00:00:00 - 23:59:59
wkday = "Mon" | "Tue" | "Wed"
| "Thu" | "Fri" | "Sat" | "Sun"
weekday = "Monday" | "Tuesday" | "Wednesday"
| "Thursday" | "Friday" | "Saturday" | "Sunday"
month = "Jan" | "Feb" | "Mar" | "Apr"
| "May" | "Jun" | "Jul" | "Aug"
| "Sep" | "Oct" | "Nov" | "Dec"
Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=RFC2616", "protocol=URI", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html"
class
HTTP_DATE
inherit
DEBUG_OUTPUT
create
make_from_timestamp,
make_from_string,
make_from_date_time
feature {NONE} -- Initialization
make_from_timestamp (n: INTEGER_64)
-- Build from unix timestamp `n'
do
internal_timestamp := n
--| FIXME: find workaround when `n' is not INTEGER_32
create date_time.make_from_epoch (n.as_integer_32)
end
make_from_string (s: READABLE_STRING_8)
-- Create from string representation `s'
-- Supports: RFC 1123 and RFC 850
-- Tolerant with: GMT+offset and GMT-offset
--| Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
--| Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
do
if attached string_to_date_time (s) as dt then
date_time := dt
elseif attached ansi_c_string_to_date_time (s) as dt then
date_time := dt
else
has_error := True
date_time := epoch
end
end
make_from_date_time (dt: DATE_TIME)
-- Build from date `dt'
do
date_time := dt
end
feature -- Access
has_error: BOOLEAN
-- Error occurred during creation with `make_from_string'?
date_time: DATE_TIME
-- Associated Date time.
string: STRING
-- String representation recommended for HTTP date.
--| Sun, 06 Nov 1994 08:49:37 GMT
do
Result := rfc1123_string
end
timestamp: INTEGER_64
-- Unix timestamp.
do
Result := internal_timestamp
if Result = 0 then
Result := date_time.definite_duration (epoch).seconds_count
internal_timestamp := Result
end
end
feature {NONE} -- Internal
epoch: DATE_TIME
once ("THREAD")
create Result.make_from_epoch (0)
end
internal_timestamp: like timestamp
internal_rfc1123_string: detachable STRING
feature -- Conversion to string
yyyy_mmm_dd_string: STRING
-- String representation YYYY mmm dd
-- 2012 Dec 25
do
create Result.make (11)
append_date_time_to_yyyy_mmm_dd_string (date_time, Result)
end
rfc1123_string: STRING
-- String representation following RFC 1123.
--| Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
local
s: like internal_rfc1123_string
do
s := internal_rfc1123_string
if s = Void then
create s.make (32)
append_date_time_to_rfc1123_string (date_time, s)
internal_rfc1123_string := s
end
Result := s
end
rfc850_string: STRING
-- String representation following RFC 850
do
create Result.make (32)
append_date_time_to_rfc850_string (date_time, Result)
end
ansi_c_string: STRING
-- ANSI C's asctime() format
do
create Result.make (32)
append_date_time_to_ansi_c_string (date_time, Result)
end
feature -- Conversion into string
append_date_time_to_yyyy_mmm_dd_string (dt: DATE_TIME; s: STRING)
do
s.append_integer (dt.year) -- yyyy
s.append_character (' ') -- ' '
append_month_mmm_to (dt.month, s) -- mmm
s.append_character (' ') -- ' '
append_2_digits_integer_to (dt.day, s) -- dd
end
append_date_time_to_rfc1123_string (dt: DATE_TIME; s: STRING)
do
append_day_ddd_to (dt.date.day_of_the_week, s) -- ddd
s.append_character (',') -- ','
s.append_character (' ') -- SPace
append_2_digits_integer_to (dt.day, s) -- dd
s.append_character (' ') -- SPace
append_month_mmm_to (dt.month, s) -- mmm
s.append_character (' ') -- SPace
s.append_integer (dt.year) -- yyyy
s.append_character (' ') -- SPace
append_2_digits_time_to (dt.time, s) -- hh:mi:ss
s.append (" GMT") -- SPace + GMT
end
append_date_time_to_rfc850_string (dt: DATE_TIME; s: STRING)
do
append_day_name_to (dt.date.day_of_the_week, s) -- mmm
s.append_character (',') -- ,
s.append_character (' ') -- SPace
append_2_digits_integer_to (dt.day, s) -- dd
s.append_character ('-') -- '-'
append_month_mmm_to (dt.month, s) -- mmm
s.append_character ('-') -- '-'
s.append_integer (dt.year \\ 100) -- yy
s.append_character (' ') -- SPace
append_2_digits_time_to (dt.time, s) -- hh:mi:ss
s.append (" GMT") -- SPace + GMT
end
append_date_time_to_ansi_c_string (dt: DATE_TIME; s: STRING)
--| Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
do
append_day_ddd_to (dt.date.day_of_the_week, s) -- ddd
s.append_character (' ') -- SP
append_month_mmm_to (dt.month, s) -- mmm
s.append_character (' ') -- SPace
s.append_character (' ') -- SPace
s.append_integer (dt.day) -- d
s.append_character (' ') -- SPace
append_2_digits_time_to (dt.time, s) -- hh:mi:ss
s.append_character (' ') -- SPace
s.append_integer (dt.year) -- yyyy
end
feature -- Status report
debug_output: STRING
do
if attached internal_rfc1123_string as st then
Result := st.string
else
create Result.make (32)
append_date_time_to_rfc1123_string (date_time, Result)
end
end
feature {NONE} -- Implementation
append_2_digits_integer_to (i: INTEGER; s: STRING)
require
is_not_negative: i >= 0
do
if i <= 9 then
s.append_character ('0')
end
s.append_integer (i)
end
append_2_digits_time_to (t: TIME; s: STRING)
do
append_2_digits_integer_to (t.hour, s) -- hh
s.append_character (':') -- :
append_2_digits_integer_to (t.minute, s) -- mi
s.append_character (':') -- :
append_2_digits_integer_to (t.second, s) -- ss
end
append_day_ddd_to (d: INTEGER; s: STRING)
require
1 <= d and d <= 7
do
inspect d
when 1 then s.append ("Sun")
when 2 then s.append ("Mon")
when 3 then s.append ("Tue")
when 4 then s.append ("Wed")
when 5 then s.append ("Thu")
when 6 then s.append ("Fri")
when 7 then s.append ("Sat")
else
-- Error
end
end
append_day_name_to (d: INTEGER; s: STRING)
require
1 <= d and d <= 7
do
inspect d
when 1 then s.append ("Sunday")
when 2 then s.append ("Monday")
when 3 then s.append ("Tuesday")
when 4 then s.append ("Wednesday")
when 5 then s.append ("Thursday")
when 6 then s.append ("Friday")
when 7 then s.append ("Saturday")
else
-- Error
end
end
append_month_mmm_to (m: INTEGER; s: STRING)
require
1 <= m and m <= 12
do
inspect m
when 1 then s.append ("Jan")
when 2 then s.append ("Feb")
when 3 then s.append ("Mar")
when 4 then s.append ("Apr")
when 5 then s.append ("May")
when 6 then s.append ("Jun")
when 7 then s.append ("Jul")
when 8 then s.append ("Aou")
when 9 then s.append ("Sep")
when 10 then s.append ("Oct")
when 11 then s.append ("Nov")
when 12 then s.append ("Dec")
else
-- Error
end
end
feature {NONE} -- Implementation
string_to_date_time (s: READABLE_STRING_8): detachable DATE_TIME
-- String representation of `dt' using the RFC 1123
-- HTTP-date = rfc1123-date | rfc850-date | asctime-date
-- rfc1123-date = wkday "," SP date1 SP time SP "GMT"
-- rfc850-date = weekday "," SP date2 SP time SP "GMT"
-- asctime-date = wkday SP date3 SP time SP 4DIGIT
-- date1 = 2DIGIT SP month SP 4DIGIT
-- ; day month year (e.g., 02 Jun 1982)
-- date2 = 2DIGIT "-" month "-" 2DIGIT
-- ; day-month-year (e.g., 02-Jun-82)
-- date3 = month SP ( 2DIGIT | ( SP 1DIGIT ))
-- ; month day (e.g., Jun 2)
-- time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
-- ; 00:00:00 - 23:59:59
-- wkday = "Mon" | "Tue" | "Wed"
-- | "Thu" | "Fri" | "Sat" | "Sun"
-- weekday = "Monday" | "Tuesday" | "Wednesday"
-- | "Thursday" | "Friday" | "Saturday" | "Sunday"
-- month = "Jan" | "Feb" | "Mar" | "Apr"
-- | "May" | "Jun" | "Jul" | "Aug"
-- | "Sep" | "Oct" | "Nov" | "Dec"
--| Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
--| Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
--| Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
note
EIS: "name=RFC2616", "protocol=URI", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html"
local
t: STRING_8
l_ddd, l_mmm: detachable STRING_8
l_dd, l_yyyy, l_hh, l_mi, l_ss, l_ff2: INTEGER
l_mo: INTEGER
l_gmt_offset: INTEGER -- minutes
i, n: INTEGER
err: BOOLEAN
do
i := 1
n := s.count
create t.make (4)
-- Skip blanks
from until i > n or else not s[i].is_space loop i := i + 1 end
--| ddd
t.wipe_out
from until i > n or else not s[i].is_alpha loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count >= 3 then -- Accept full day string
l_ddd := t.as_lower
else
err := True
end
--| blanks
from until i > n or else not s[i].is_space loop i := i + 1 end
--| ,[0]dd
if not err and i <= n and s[i] = ',' then
i := i + 1
from until i > n or else not s[i].is_space loop i := i + 1 end
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count > 0 then
check t.is_integer end
l_dd := t.to_integer
else
err := True
end
else
err := True
end
--| blanks or '-'
if s[i] = '-' then
i := i + 1
else
from until i > n or else not s[i].is_space loop i := i + 1 end
end
--| mmm
if not err then
t.wipe_out
from until i > n or else not s[i].is_alpha loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count >= 3 then
l_mmm := t.as_upper
if l_mmm.count > 3 then
-- Tolerant to full month name ..
l_mmm.keep_head (3)
end
if l_mmm.same_string ("JAN") then l_mo := 01
elseif l_mmm.same_string ("FEB") then l_mo := 02
elseif l_mmm.same_string ("MAR") then l_mo := 03
elseif l_mmm.same_string ("APR") then l_mo := 04
elseif l_mmm.same_string ("MAY") then l_mo := 05
elseif l_mmm.same_string ("JUN") then l_mo := 06
elseif l_mmm.same_string ("JUL") then l_mo := 07
elseif l_mmm.same_string ("AOU") then l_mo := 08
elseif l_mmm.same_string ("SEP") then l_mo := 09
elseif l_mmm.same_string ("OCT") then l_mo := 10
elseif l_mmm.same_string ("NOV") then l_mo := 11
elseif l_mmm.same_string ("DEC") then l_mo := 12
else err := True
end
else
err := True
end
end
--| blanks or '-'
if s[i] = '-' then
i := i + 1
else
from until i > n or else not s[i].is_space loop i := i + 1 end
end
--| yyyy
if not err then
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count > 0 then
check t.count = 4 or t.count = 2 and t.is_integer end
l_yyyy := t.to_integer
if t.count = 2 then
-- RFC 850
l_yyyy := 1900 + l_yyyy
end
else
err := True
end
end
--| blank
from until i > n or else not s[i].is_space loop i := i + 1 end
--| [0]hh:
if not err then
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count > 0 and s[i] = ':' then
check t.count = 2 and t.is_integer end
l_hh := t.to_integer
i := i + 1
else
err := True
end
end
--| [0]mi:
if not err then
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count > 0 and s[i] = ':' then
check t.count = 2 and t.is_integer end
l_mi := t.to_integer
i := i + 1
else
err := True
end
end
--| [0]ss
if not err then
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count > 0 then
check t.count = 2 and t.is_integer end
l_ss := t.to_integer
else
err := True
end
end
--| .ff2
if not err and s[i] = '.' then
--| .ff2
i := i + 1
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count > 0 then
check t.is_integer end
l_ff2 := t.to_integer
else
err := True
end
end
if not err then
from until i > n or else not s[i].is_space loop i := i + 1 end
t.wipe_out
from until i > n or else not s[i].is_alpha loop
t.extend (s[i].as_upper)
i := i + 1
end
if t.same_string ("GMT") or t.same_string ("UTC") then
from until i > n or else not s[i].is_space loop i := i + 1 end
if i <= n then
t.wipe_out
if s[i] = '+' then
t.extend (s[i])
elseif s[i] = '-' then
t.extend (s[i])
else
err := True
end
if not err then
i := i + 1
from until i > n or else not s[i].is_space loop i := i + 1 end
from until i > n or else not s[i].is_digit loop
t.extend (s[i].as_upper)
i := i + 1
end
l_gmt_offset := t.to_integer * 60
if i <= n and s[i] = ':' then
i := i + 1
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i].as_upper)
i := i + 1
end
l_gmt_offset := l_gmt_offset + l_gmt_offset.sign * t.to_integer
end
end
end
else
err := True
end
end
if not err then
check
valid_yyyy: 0 < l_yyyy
valid_dd: 0 < l_dd and l_dd <= 31
valid_mo: 0 < l_mo and l_mo <= 12
valid_hh: 0 <= l_hh and l_hh <= 23
valid_mi: 0 <= l_mi and l_mi <= 59
valid_ss: 0 <= l_ss and l_ss <= 59
end
create Result.make (l_yyyy, l_mo, l_dd, l_hh, l_mi, l_ss)
if l_gmt_offset /= 0 then
Result.minute_add (- l_gmt_offset)
end
else
-- Void is better than wrong date.
end
end
ansi_c_string_to_date_time (s: READABLE_STRING_8): detachable DATE_TIME
-- String representation of `dt' using the RFC 1123
-- asctime-date = wkday SP date3 SP time SP 4DIGIT
-- date3 = month SP ( 2DIGIT | ( SP 1DIGIT ))
-- ; month day (e.g., Jun 2)
-- time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
-- ; 00:00:00 - 23:59:59
-- wkday = "Mon" | "Tue" | "Wed"
-- | "Thu" | "Fri" | "Sat" | "Sun"
-- month = "Jan" | "Feb" | "Mar" | "Apr"
-- | "May" | "Jun" | "Jul" | "Aug"
-- | "Sep" | "Oct" | "Nov" | "Dec"
--| Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
note
EIS: "name=RFC2616", "protocol=URI", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html"
local
t: STRING_8
l_ddd, l_mmm: detachable STRING_8
l_dd, l_yyyy, l_hh, l_mi, l_ss, l_ff2: INTEGER
l_mo: INTEGER
l_gmt_offset: INTEGER -- minutes
i, n: INTEGER
err: BOOLEAN
do
i := 1
n := s.count
create t.make (4)
-- Skip blanks
from until i > n or else not s[i].is_space loop i := i + 1 end
--| ddd
t.wipe_out
from until i > n or else not s[i].is_alpha loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count >= 3 then -- Accept full day string
l_ddd := t.as_lower
else
err := True
end
--| blanks
from until i > n or else not s[i].is_space loop i := i + 1 end
--| mmm
if not err then
t.wipe_out
from until i > n or else not s[i].is_alpha loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count >= 3 then
l_mmm := t.as_upper
if l_mmm.count > 3 then
-- Tolerant to full month name ..
l_mmm.keep_head (3)
end
if l_mmm.same_string ("JAN") then l_mo := 01
elseif l_mmm.same_string ("FEB") then l_mo := 02
elseif l_mmm.same_string ("MAR") then l_mo := 03
elseif l_mmm.same_string ("APR") then l_mo := 04
elseif l_mmm.same_string ("MAY") then l_mo := 05
elseif l_mmm.same_string ("JUN") then l_mo := 06
elseif l_mmm.same_string ("JUL") then l_mo := 07
elseif l_mmm.same_string ("AOU") then l_mo := 08
elseif l_mmm.same_string ("SEP") then l_mo := 09
elseif l_mmm.same_string ("OCT") then l_mo := 10
elseif l_mmm.same_string ("NOV") then l_mo := 11
elseif l_mmm.same_string ("DEC") then l_mo := 12
else err := True
end
else
err := True
end
end
--| blanks
from until i > n or else not s[i].is_space loop i := i + 1 end
--| dd
if not err and i <= n then
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count > 0 then
check t.is_integer end
l_dd := t.to_integer
else
err := True
end
else
err := True
end
--| blanks
from until i > n or else not s[i].is_space loop i := i + 1 end
--| [0]hh:
if not err then
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count > 0 and s[i] = ':' then
check t.count = 2 and t.is_integer end
l_hh := t.to_integer
i := i + 1
else
err := True
end
end
--| [0]mi:
if not err then
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count > 0 and s[i] = ':' then
check t.count = 2 and t.is_integer end
l_mi := t.to_integer
i := i + 1
else
err := True
end
end
--| [0]ss
if not err then
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count > 0 then
check t.count = 2 and t.is_integer end
l_ss := t.to_integer
else
err := True
end
end
--| .ff2
if not err and s[i] = '.' then
--| .ff2
i := i + 1
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if i <= n and t.count > 0 then
check t.is_integer end
l_ff2 := t.to_integer
else
err := True
end
end
--| blanks
from until i > n or else not s[i].is_space loop i := i + 1 end
--| yyyy
if not err then
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i])
i := i + 1
end
if t.count > 0 then
check t.count = 4 or t.count = 2 and t.is_integer end
l_yyyy := t.to_integer
if t.count = 2 then
-- RFC 850
l_yyyy := 1900 + l_yyyy
end
else
err := True
end
end
--| blank
from until i > n or else not s[i].is_space loop i := i + 1 end
if i <= n and not err then
from until i > n or else not s[i].is_space loop i := i + 1 end
t.wipe_out
from until i > n or else not s[i].is_alpha loop
t.extend (s[i].as_upper)
i := i + 1
end
if t.same_string ("GMT") or t.same_string ("UTC") then
from until i > n or else not s[i].is_space loop i := i + 1 end
if i <= n then
t.wipe_out
if s[i] = '+' then
t.extend (s[i])
elseif s[i] = '-' then
t.extend (s[i])
else
err := True
end
if not err then
i := i + 1
from until i > n or else not s[i].is_space loop i := i + 1 end
from until i > n or else not s[i].is_digit loop
t.extend (s[i].as_upper)
i := i + 1
end
l_gmt_offset := t.to_integer * 60
if i <= n and s[i] = ':' then
i := i + 1
t.wipe_out
from until i > n or else not s[i].is_digit loop
t.extend (s[i].as_upper)
i := i + 1
end
l_gmt_offset := l_gmt_offset + l_gmt_offset.sign * t.to_integer
end
end
end
else
err := True
end
end
if not err then
check
valid_yyyy: 0 < l_yyyy
valid_dd: 0 < l_dd and l_dd <= 31
valid_mo: 0 < l_mo and l_mo <= 12
valid_hh: 0 <= l_hh and l_hh <= 23
valid_mi: 0 <= l_mi and l_mi <= 59
valid_ss: 0 <= l_ss and l_ss <= 59
end
create Result.make (l_yyyy, l_mo, l_dd, l_hh, l_mi, l_ss)
if l_gmt_offset /= 0 then
Result.minute_add (- l_gmt_offset)
end
else
-- Void is better than wrong date.
end
end
invariant
note
copyright: "2011-2013, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -69,23 +69,9 @@ feature {NONE} -- Initialization
make_from_raw_header_data (h: READABLE_STRING_8)
-- Create Current from raw header data
local
line : detachable STRING
lines: LIST [READABLE_STRING_8]
do
lines := h.split ('%N')
make_with_count (lines.count)
across
lines as c
loop
line := c.item
if not line.is_empty then
if line [line.count] = '%R' then
line.remove_tail (1)
end
add_header (line)
end
end
make
append_raw_header_data (h)
end
feature -- Recycle
@@ -111,23 +97,19 @@ feature -- Access
end
headers: ARRAYED_LIST [READABLE_STRING_8]
-- Header's lines
-- Header's lines.
string: STRING_8
-- String representation of the headers
-- String representation of the header entries.
local
l_headers: like headers
n: like count
do
l_headers := headers
if not l_headers.is_empty then
create Result.make (l_headers.count * 32)
across
l_headers as c
loop
append_line_to (c.item, Result)
end
else
n := count
if n = 0 then
create Result.make_empty
else
create Result.make (n * 32)
append_string_to (Result)
end
ensure
result_has_ending_cr_lf: Result.count >= 2 implies Result.substring (Result.count - 1, Result.count).same_string ("%R%N")
@@ -135,6 +117,7 @@ feature -- Access
end
to_name_value_iterable: ITERABLE [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]]
-- Iterable representation of the header entries.
local
res: ARRAYED_LIST [TUPLE [READABLE_STRING_8, READABLE_STRING_8]]
do
@@ -149,15 +132,53 @@ feature -- Access
Result := res
end
feature -- Conversion
append_string_to (a_result: STRING_8)
-- Append current as string representation to `a_result'
local
l_headers: like headers
do
l_headers := headers
if not l_headers.is_empty then
across
l_headers as c
loop
append_line_to (c.item, a_result)
end
end
end
feature -- Access
new_cursor: INDEXABLE_ITERATION_CURSOR [READABLE_STRING_8]
-- Fresh cursor associated with current structure
-- Fresh cursor associated with current structure.
do
Result := headers.new_cursor
end
feature -- Header: filling
feature -- Header: adding
append_raw_header_data (h: READABLE_STRING_8)
-- Append raw header data `h' to Current
local
line : detachable STRING
lines: LIST [READABLE_STRING_8]
do
lines := h.split ('%N')
headers.grow (headers.count + lines.count)
across
lines as c
loop
line := c.item
if not line.is_empty then
if line [line.count] = '%R' then
line.remove_tail (1)
end
add_header (line)
end
end
end
append_array (a_headers: ARRAY [TUPLE [key: READABLE_STRING_8; value: READABLE_STRING_8]])
-- Append array of key,value headers
@@ -166,7 +187,7 @@ feature -- Header: filling
across
a_headers as c
loop
put_header_key_value (c.item.key, c.item.value)
add_header_key_value (c.item.key, c.item.value)
end
end
@@ -181,6 +202,54 @@ feature -- Header: filling
end
end
feature -- Header: merging
put_raw_header_data (h: READABLE_STRING_8)
-- Append raw header data `h' to Current
-- Overwrite existing header with same name
local
line : detachable STRING
lines: LIST [READABLE_STRING_8]
do
lines := h.split ('%N')
headers.grow (headers.count + lines.count)
across
lines as c
loop
line := c.item
if not line.is_empty then
if line [line.count] = '%R' then
line.remove_tail (1)
end
put_header (line)
end
end
end
put_array (a_headers: ARRAY [TUPLE [key: READABLE_STRING_8; value: READABLE_STRING_8]])
-- Append array of key,value headers
-- Overwrite existing header with same name
do
headers.grow (headers.count + a_headers.count)
across
a_headers as c
loop
put_header_key_value (c.item.key, c.item.value)
end
end
put_header_object (h: HTTP_HEADER)
-- Append headers from `h'
-- Overwrite existing header with same name
do
headers.grow (headers.count + h.headers.count)
across
h.headers as c
loop
put_header (c.item.string)
end
end
feature -- Header change: general
add_header (h: READABLE_STRING_8)
@@ -203,14 +272,52 @@ feature -- Header change: general
add_header_key_value (k,v: READABLE_STRING_8)
-- Add header `k:v', or replace existing header of same header name/key
local
s: STRING_8
do
add_header (k + colon_space + v)
create s.make (k.count + 2 + v.count)
s.append (k)
s.append (colon_space)
s.append (v)
add_header (s)
end
put_header_key_value (k,v: READABLE_STRING_8)
-- Add header `k:v', or replace existing header of same header name/key
local
s: STRING_8
do
put_header (k + colon_space + v)
create s.make (k.count + 2 + v.count)
s.append (k)
s.append (colon_space)
s.append (v)
put_header (s)
end
put_header_key_values (k: READABLE_STRING_8; a_values: ITERABLE [READABLE_STRING_8]; a_separator: detachable READABLE_STRING_8)
-- Add header `k: a_values', or replace existing header of same header values/key.
-- Use `comma_space' as default separator if `a_separator' is Void or empty.
local
s: STRING_8
l_separator: READABLE_STRING_8
do
if a_separator /= Void and then not a_separator.is_empty then
l_separator := a_separator
else
l_separator := comma_space
end
create s.make_empty
across
a_values as c
loop
if not s.is_empty then
s.append_string (l_separator)
end
s.append (c.item)
end
if not s.is_empty then
put_header_key_value (k, s)
end
end
put_header_key_methods (k: READABLE_STRING_8; a_methods: ITERABLE [READABLE_STRING_8])
@@ -447,7 +554,7 @@ feature -- Method related
put_allow (a_methods: ITERABLE [READABLE_STRING_8])
-- If `a_methods' is not empty, put `Allow' header with list `a_methods' of methods
do
put_header_key_methods ({HTTP_HEADER_NAMES}.header_allow, a_methods)
put_header_key_values ({HTTP_HEADER_NAMES}.header_allow, a_methods, Void)
end
feature -- Date
@@ -552,13 +659,16 @@ feature -- Cookie
if
domain /= Void and then not domain.same_string ("localhost")
then
s.append ("; Domain=" + domain)
s.append ("; Domain=")
s.append (domain)
end
if path /= Void then
s.append ("; Path=" + path)
s.append ("; Path=")
s.append (path)
end
if expiration /= Void then
s.append ("; Expires=" + expiration)
s.append ("; Expires=")
s.append (expiration)
end
if secure then
s.append ("; Secure")
@@ -756,8 +866,11 @@ feature {NONE} -- Implementation
date_to_rfc1123_http_date_format (dt: DATE_TIME): STRING_8
-- String representation of `dt' using the RFC 1123
local
d: HTTP_DATE
do
Result := dt.formatted_out ("ddd, [0]dd mmm yyyy [0]hh:[0]mi:[0]ss") + " GMT"
create d.make_from_date_time (dt)
Result := d.string
end
feature {NONE} -- Constants
@@ -765,8 +878,20 @@ feature {NONE} -- Constants
str_binary: STRING = "binary"
str_chunked: STRING = "chunked"
colon_space: STRING = ": "
semi_colon_space: STRING = "; "
colon_space: IMMUTABLE_STRING_8
once
create Result.make_from_string (": ")
end
semi_colon_space: IMMUTABLE_STRING_8
once
create Result.make_from_string ("; ")
end
comma_space: IMMUTABLE_STRING_8
once
create Result.make_from_string (", ")
end
note
copyright: "2011-2013, Jocelyn Fiat, Eiffel Software and others"

View File

@@ -0,0 +1,15 @@
class
AUTOTEST
create
make
feature {NONE} -- Initialization
make
-- Initialize `Current'.
do
end
end

View File

@@ -0,0 +1,77 @@
note
description: "[
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
testing: "type/manual"
class
HTTP_DATE_TEST_SET
inherit
EQA_TEST_SET
feature -- Test routines
test_http_date
-- New test routine
local
s: STRING
d: HTTP_DATE
do
s := "Sun, 06 Nov 1994 08:49:37 GMT"
create d.make_from_string (s)
assert ("RFC 1123", not d.has_error and then d.string.same_string (s))
create d.make_from_timestamp (d.timestamp)
assert ("RFC 1123", not d.has_error and then d.string.same_string (s))
s := "Sunday, 06-Nov-94 08:49:37 GMT"
create d.make_from_string (s)
assert ("RFC 850", not d.has_error and then d.rfc850_string.same_string (s))
create d.make_from_timestamp (d.timestamp)
assert ("RFC 850", not d.has_error and then d.rfc850_string.same_string (s))
s := "Sun, 06 Nov 1994 08:49:37 GMT"
create d.make_from_string (s)
assert ("ANSI C format", not d.has_error and then d.ansi_c_string.same_string ("Sun Nov 6 08:49:37 1994"))
s := "Sun Nov 6 08:49:37 1994"
create d.make_from_string (s)
assert ("ANSI C format", not d.has_error and then d.ansi_c_string.same_string (s))
-- Tolerance ...
s := "Sun, 06 November 1994 09:49:37 GMT+1"
create d.make_from_string (s)
assert ("RFC 1123", not d.has_error and then d.string.same_string ("Sun, 06 Nov 1994 08:49:37 GMT"))
s := "Sun, 06 Nov 1994 09:49:37 GMT+1"
create d.make_from_string (s)
assert ("RFC 1123", not d.has_error and then d.string.same_string ("Sun, 06 Nov 1994 08:49:37 GMT"))
s := "Sun, 06 Nov 1994 07:49:37 GMT-1"
create d.make_from_string (s)
assert ("RFC 1123", not d.has_error and then d.string.same_string ("Sun, 06 Nov 1994 08:49:37 GMT"))
s := "Sun, 06 Nov 1994 10:19:37 GMT+1:30"
create d.make_from_string (s)
assert ("RFC 1123", not d.has_error and then d.string.same_string ("Sun, 06 Nov 1994 08:49:37 GMT"))
s := "Sun, 06 Nov 1994 07:19:37 GMT-1:30"
create d.make_from_string (s)
assert ("RFC 1123", not d.has_error and then d.string.same_string ("Sun, 06 Nov 1994 08:49:37 GMT"))
s := "Thu, 31 Jan 2013 15:35:00 GMT+5:45" -- NPT
create d.make_from_string (s)
assert ("RFC 1123", not d.has_error and then d.string.same_string ("Thu, 31 Jan 2013 09:50:00 GMT"))
s := "Thu, 31 Jan 2013 05:20:00 GMT-4:30" -- VET
create d.make_from_string (s)
assert ("RFC 1123", not d.has_error and then d.string.same_string ("Thu, 31 Jan 2013 09:50:00 GMT"))
end
end

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="tests" uuid="0582ACC2-11D8-4FE5-888D-61837BA8F43E">
<target name="tests">
<root class="AUTOTEST" feature="make"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard">
</option>
<setting name="concurrency" value="none"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="http" location="..\http-safe.ecf" readonly="false"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<tests name="src" location=".\" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="tests" uuid="0582ACC2-11D8-4FE5-888D-61837BA8F43E">
<target name="tests">
<root class="ANY" feature="default_create"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" void_safety="none" syntax="standard">
</option>
<setting name="concurrency" value="none"/>
<library name="http" location="..\http.ecf"/>
<library name="base" location="$ISE_LIBRARY/library/base/base.ecf"/>
<library name="testing" location="$ISE_LIBRARY/library/testing/testing.ecf"/>
<tests name="src" location="." recursive="true"/>
</target>
</system>