Merge pull request #128 from jocelyn/response_header

Extracting HTTP_HEADER_BUILDER from HTTP_HEADER
Improving wsf session usage
Various unicode related improvement for router and error library.
This commit is contained in:
Jocelyn Fiat
2014-05-14 10:06:58 +02:00
19 changed files with 944 additions and 619 deletions

View File

@@ -376,10 +376,11 @@ feature -- Error reporting
local
h: HTTP_HEADER
m: READABLE_STRING_8
utf: UTF_CONVERTER
do
m := req.error_handler.as_string_representation
m := utf.string_32_to_utf_8_string_8 (req.error_handler.as_string_representation)
create h.make
h.put_content_type_text_plain
h.put_content_type_utf_8_text_plain
h.put_content_length (m.count)
res.set_status_code (req.error_handler.primary_error_code)
res.put_header_lines (h)

View File

@@ -98,8 +98,8 @@ feature {WSF_RESPONSE} -- Output
local
h: HTTP_HEADER
l_description: STRING_8
l_base_url: STRING_8
l_api_resource: detachable STRING_8
l_base_url: READABLE_STRING_8
l_api_resource: detachable READABLE_STRING_8
do
create h.make
h.put_content_type_text_html
@@ -132,7 +132,7 @@ feature {WSF_RESPONSE} -- Output
if attached router.base_url as u then
l_base_url := u
else
create l_base_url.make_empty
create {STRING_8} l_base_url.make_empty
end
debug
@@ -324,7 +324,7 @@ feature {NONE} -- Implementation
end
note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2014, 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

View File

@@ -3,8 +3,8 @@ note
Entry of WSF_ROUTER
It contains
- mapping
- request methods
- request methods
]"
date: "$Date$"
revision: "$Revision$"
@@ -40,20 +40,23 @@ feature -- Access
feature -- Status report
debug_output: STRING
debug_output: READABLE_STRING_GENERAL
-- String that should be displayed in debugger to represent `Current'.
local
s: STRING_32
do
create Result.make_from_string (mapping.debug_output)
create s.make_from_string_general (mapping.debug_output)
if attached request_methods as mtds then
Result.append_string (" [ ")
s.append_string (" [ ")
across
mtds as c
loop
Result.append_string (c.item)
Result.append_string (" ")
s.append_string (c.item)
s.append_string (" ")
end
Result.append_string ("]")
s.append_string ("]")
end
Result := s
end
feature -- Change
@@ -68,7 +71,7 @@ invariant
mapping_attached: mapping /= Void
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2014, 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

View File

@@ -48,10 +48,10 @@ feature -- Documentation
feature -- Status report
debug_output: STRING
debug_output: READABLE_STRING_GENERAL
-- String that should be displayed in debugger to represent `Current'.
do
Result := description.as_string_8 + " : " + associated_resource
Result := description + {STRING_32} " : " + associated_resource.to_string_32
end
feature -- Status
@@ -88,7 +88,7 @@ feature -- Helper
end
note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2014, 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

View File

@@ -45,14 +45,14 @@ feature {NONE} -- Execution
feature -- Status report
debug_output: STRING
debug_output: READABLE_STRING_GENERAL
-- String that should be displayed in debugger to represent `Current'.
do
Result := Precursor + " {" + ({C}).name + "}"
end
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2014, 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

View File

@@ -22,14 +22,14 @@ feature -- Access
feature -- Status report
debug_output: STRING
debug_output: READABLE_STRING_GENERAL
-- String that should be displayed in debugger to represent `Current'.
do
Result := Precursor + " {" + ({C}).name + "}"
end
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2014, 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

View File

@@ -60,15 +60,16 @@ feature {NONE} -- Initialization
feature -- Cookie
apply_to (h: HTTP_HEADER; a_request: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
apply_to (h: HTTP_HEADER_MODIFIER; a_request: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
-- <Precursor>
local
dt: detachable DATE_TIME
l_domain: detachable READABLE_STRING_8
do
l_domain := a_request.server_name
if l_domain.same_string ("localhost") then
-- Due to limitation of specific handling of local cookies
-- it is recommended to use Void or IP instead of "localhost"
-- Due to limitation of specific handling of local cookies
-- it is recommended to use Void or IP instead of "localhost"
l_domain := Void
end
if is_destroyed then
@@ -79,13 +80,18 @@ feature -- Cookie
create dt.make_now_utc
dt.day_add (40)
end
h.put_cookie_with_expiration_date (cookie_name, uuid, dt, a_path, l_domain, False, True)
h.put_cookie_with_expiration_date (cookie_name, id, dt, a_path, l_domain, False, True)
end
end
cookie_name: READABLE_STRING_8
feature -- Access
feature -- Access
id: READABLE_STRING_8
do
Result := uuid
end
uuid: READABLE_STRING_8
@@ -135,8 +141,8 @@ feature {NONE} -- Storage
load
do
if manager.session_exists (uuid) then
if attached manager.session_data (uuid) as d then
if manager.session_exists (id) then
if attached manager.session_data (id) as d then
data := d
set_expiration (data.expiration)
else
@@ -177,7 +183,7 @@ feature {NONE} -- Implementation
end
note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2014, 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

View File

@@ -68,7 +68,7 @@ feature -- Persistence
delete_session (a_session)
else
ensure_session_folder_exists
create f.make_with_path (file_name (a_session.uuid))
create f.make_with_path (file_name (a_session.id))
if not f.exists or else f.is_writable then
f.create_read_write
a_session.data.set_expiration (a_session.expiration)
@@ -91,7 +91,7 @@ feature -- Persistence
rescued: BOOLEAN
do
if not rescued then
create f.make_with_path (file_name (a_session.uuid))
create f.make_with_path (file_name (a_session.id))
if f.exists then
f.delete
end

View File

@@ -7,26 +7,43 @@ note
deferred class
WSF_SESSION
feature -- Access
feature -- Access
id: READABLE_STRING_8
-- Session identifier.
deferred
end
uuid: READABLE_STRING_8
obsolete
"Use `id' which is more general [2014-03]"
deferred
end
data: WSF_SESSION_DATA
-- Data associated with current session.
deferred
end
expiration: detachable DATE_TIME
-- Expiration date for current session, if any.
deferred
end
expired: BOOLEAN
-- Is current session expired now?
do
Result := expired_at (create {DATE_TIME}.make_now_utc)
end
expired_at (dt: DATE_TIME): BOOLEAN
-- Is current session expired at date and time `dt'?
do
if attached expiration as e then
Result := e < (create {DATE_TIME}.make_now_utc)
Result := e < (dt)
end
end
feature -- status
is_pending: BOOLEAN
@@ -36,27 +53,32 @@ feature -- status
end
is_destroyed: BOOLEAN
-- Is current session in destroyed state?
deferred
end
feature -- Entries
table: TABLE_ITERABLE [detachable ANY, READABLE_STRING_32]
table: TABLE_ITERABLE [detachable ANY, READABLE_STRING_GENERAL]
-- Table of session data indexed by key
do
Result := data
end
item (k: READABLE_STRING_GENERAL): detachable ANY
item alias "[]" (k: READABLE_STRING_GENERAL): detachable ANY assign remember
-- Session value associated with key `k'.
do
Result := data.item (table_key (k))
end
remember (v: detachable ANY; k: READABLE_STRING_GENERAL)
-- Remember value `v' in association with key `k'.
do
data.force (v, table_key (k))
end
forget (k: READABLE_STRING_GENERAL)
-- Forget about value associated with key `k'.
do
data.remove (table_key (k))
end
@@ -71,19 +93,30 @@ feature {NONE} -- Implementation
feature -- Control
destroy
-- Destroy current session.
deferred
end
commit
-- Commit current session, including data associated.
deferred
end
apply_to (h: HTTP_HEADER; req: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
apply_to (h: HTTP_HEADER_MODIFIER; req: WSF_REQUEST; a_path: detachable READABLE_STRING_8)
-- Apply current session to header `h' for request `req' and optional path `a_path'.
-- note: either use `apply_to' or `apply', not both.
deferred
end
apply (req: WSF_REQUEST; res: WSF_RESPONSE; a_path: detachable READABLE_STRING_8)
-- Apply current session to response `res' for request `req' and optional path `a_path'.
-- note: either use `apply' or `apply_to', not both.
do
apply_to (res.header, req, a_path)
end
note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2014, 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

View File

@@ -8,7 +8,13 @@ class
WSF_SESSION_DATA
inherit
HASH_TABLE [detachable ANY, READABLE_STRING_32]
STRING_TABLE [detachable ANY]
rename
make as old_make,
make_caseless as make
redefine
empty_duplicate
end
create
make
@@ -24,4 +30,22 @@ feature -- Element change
expiration := dt
end
feature {NONE} -- Duplication
empty_duplicate (n: INTEGER): like Current
-- Create an empty copy of Current that can accommodate `n' items
do
create Result.make (n)
end
note
copyright: "2011-2014, 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
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

@@ -45,7 +45,7 @@ feature {WSF_RESPONSE} -- Output
req := request
if attached req.raw_header_data as l_header then
create s.make (l_header.count)
s.append (l_header.to_string_8)
s.append (l_header.to_string_8) -- Is valid as string 8, as ensured by req.raw_header_data
s.append_character ('%N')
else
create s.make_empty
@@ -99,7 +99,7 @@ feature {WSF_RESPONSE} -- Output
end
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
copyright: "2011-2014, 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

View File

@@ -1287,41 +1287,43 @@ feature {NONE} -- Cookies
local
i,j,p,n: INTEGER
l_cookies: like internal_cookies_table
s32: READABLE_STRING_32
k,v,s: STRING
do
l_cookies := internal_cookies_table
if l_cookies = Void then
create l_cookies.make_equal (0)
if attached {WSF_STRING} meta_variable ({WSF_META_NAMES}.http_cookie) as val then
s := val.value
create l_cookies.make_equal (5)
from
n := s.count
p := 1
i := 1
until
p < 1
loop
i := s.index_of ('=', p)
if i > 0 then
j := s.index_of (';', i)
if j = 0 then
j := n + 1
k := s.substring (p, i - 1)
v := s.substring (i + 1, n)
s32 := val.value
if s32.is_valid_as_string_8 then
s := s32.to_string_8
from
n := s.count
p := 1
i := 1
until
p < 1
loop
i := s.index_of ('=', p)
if i > 0 then
j := s.index_of (';', i)
if j = 0 then
j := n + 1
k := s.substring (p, i - 1)
v := s.substring (i + 1, n)
p := 0 -- force termination
else
k := s.substring (p, i - 1)
v := s.substring (i + 1, j - 1)
p := j + 1
p := 0 -- force termination
else
k := s.substring (p, i - 1)
v := s.substring (i + 1, j - 1)
p := j + 1
end
k.left_adjust
k.right_adjust
add_value_to_table (k, v, l_cookies)
end
k.left_adjust
k.right_adjust
add_value_to_table (k, v, l_cookies)
end
end
else
create l_cookies.make_equal (0)
end
internal_cookies_table := l_cookies
end

View File

@@ -35,7 +35,7 @@ feature {NONE} -- Initialization
wres: detachable WSF_WGI_DELAYED_HEADER_RESPONSE
do
transfered_content_length := 0
create header.make
create internal_header.make
wgi_response := r
if attached {WSF_WGI_DELAYED_HEADER_RESPONSE} r as r_delayed then
r_delayed.update_wsf_response (Current)
@@ -53,7 +53,7 @@ feature {NONE} -- Initialization
do
transfered_content_length := 0
wgi_response := res.wgi_response
header := res.header
internal_header := res.internal_header
set_status_code ({HTTP_STATUS_CODE}.ok) -- Default value
end
@@ -62,7 +62,7 @@ feature {WSF_RESPONSE, WSF_RESPONSE_EXPORTER} -- Properties
wgi_response: WGI_RESPONSE
-- Associated WGI_RESPONSE.
header: WSF_HEADER
internal_header: WSF_HEADER
-- Associated response header.
feature {WSF_RESPONSE_EXPORTER} -- Change
@@ -158,7 +158,7 @@ feature {WSF_RESPONSE_EXPORTER} -- Header output operation
-- commit status code and reason phrase
wgi_response.set_status_code (status_code, status_reason_phrase)
-- commit header text
wgi_response.put_header_text (header.string)
wgi_response.put_header_text (internal_header.string)
end
ensure
status_committed: status_committed
@@ -170,6 +170,26 @@ feature {WSF_RESPONSE_EXPORTER} -- Header output operation
put_error ("Content already sent, new header text ignored!")
end
feature -- Header access
header: HTTP_HEADER_MODIFIER
-- Associated header builder interface.
local
res: like internal_response_header
do
res := internal_response_header
if res = Void then
create {WSF_RESPONSE_HEADER} res.make_with_response (Current)
internal_response_header := res
end
Result := res
end
feature {NONE} -- Header access
internal_response_header: detachable like header
-- Cached version of `header'.
feature -- Header output operation
put_header_line (h: READABLE_STRING_8)
@@ -181,7 +201,7 @@ feature -- Header output operation
if header_committed then
report_content_already_sent_and_header_ignored
else
header.put_header (h)
internal_header.put_header (h)
end
end
@@ -194,7 +214,7 @@ feature -- Header output operation
if header_committed then
report_content_already_sent_and_header_ignored
else
header.add_header (h)
internal_header.add_header (h)
end
end
@@ -209,7 +229,7 @@ feature -- Header output operation
if header_committed then
report_content_already_sent_and_header_ignored
else
header.put_raw_header_data (a_text)
internal_header.put_raw_header_data (a_text)
end
ensure
message_writable: message_writable
@@ -227,7 +247,7 @@ feature -- Header output operation
if header_committed then
report_content_already_sent_and_header_ignored
else
header.append_raw_header_data (a_text)
internal_header.append_raw_header_data (a_text)
end
ensure
status_set: status_is_set
@@ -496,7 +516,7 @@ feature -- Error reporting
end
note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
copyright: "2011-2014, 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

View File

@@ -0,0 +1,64 @@
note
description: "[
Interface to build the http header associated with WSF_RESPONSE.
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_RESPONSE_HEADER
inherit
HTTP_HEADER_MODIFIER
WSF_RESPONSE_EXPORTER -- to access WSF_RESPONSE.internal_header
create
make_with_response
feature {NONE} -- Initialization
make_with_response (res: WSF_RESPONSE)
do
response := res
end
feature -- Access
response: WSF_RESPONSE
feature -- Access
new_cursor: INDEXABLE_ITERATION_CURSOR [READABLE_STRING_8]
-- Fresh cursor associated with current structure.
do
Result := response.internal_header.new_cursor
end
feature -- Header change: core
add_header (h: READABLE_STRING_8)
-- Add header `h'
-- if it already exists, there will be multiple header with same name
-- which can also be valid
do
response.add_header_line (h)
end
put_header (h: READABLE_STRING_8)
-- Add header `h' or replace existing header of same header name
do
response.put_header_line (h)
end
note
copyright: "2011-2014, 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
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