reorganized router library
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
note
|
||||
description: "Summary description for {REQUEST_FORMAT_UTILITY}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
REQUEST_FORMAT_UTILITY
|
||||
|
||||
feature -- Access
|
||||
|
||||
accepted_content_types (req: WGI_REQUEST): detachable ARRAYED_LIST [READABLE_STRING_8]
|
||||
local
|
||||
l_accept: detachable READABLE_STRING_32
|
||||
s: STRING_8
|
||||
q: READABLE_STRING_8
|
||||
p: INTEGER
|
||||
lst: LIST [READABLE_STRING_8]
|
||||
qs: QUICK_SORTER [READABLE_STRING_8]
|
||||
do
|
||||
l_accept := req.http_accept
|
||||
--TEST l_accept := "text/html,application/xhtml+xml;q=0.6,application/xml;q=0.2,text/plain;q=0.5,*/*;q=0.8"
|
||||
|
||||
if l_accept /= Void then
|
||||
lst := l_accept.as_string_8.split (',')
|
||||
create Result.make (lst.count)
|
||||
from
|
||||
lst.start
|
||||
until
|
||||
lst.after
|
||||
loop
|
||||
s := lst.item
|
||||
p := s.substring_index (";q=", 1)
|
||||
if p > 0 then
|
||||
q := s.substring (p + 3, s.count)
|
||||
s := s.substring (1, p - 1)
|
||||
else
|
||||
q := "1.0"
|
||||
end
|
||||
Result.force (q + ":" + s)
|
||||
|
||||
lst.forth
|
||||
end
|
||||
create qs.make (create {COMPARABLE_COMPARATOR [READABLE_STRING_8]})
|
||||
qs.reverse_sort (Result)
|
||||
from
|
||||
Result.start
|
||||
until
|
||||
Result.after
|
||||
loop
|
||||
s := Result.item
|
||||
p := s.index_of (':', 1)
|
||||
if p > 0 then
|
||||
s.remove_head (p)
|
||||
else
|
||||
check should_have_colon: False end
|
||||
end
|
||||
Result.forth
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
string_in_array (arr: ARRAY [STRING]; s: STRING): BOOLEAN
|
||||
local
|
||||
i,n: INTEGER
|
||||
do
|
||||
from
|
||||
i := arr.lower
|
||||
n := arr.upper
|
||||
until
|
||||
i > n or Result
|
||||
loop
|
||||
Result := s.same_string (arr[i])
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, 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
|
||||
@@ -0,0 +1,101 @@
|
||||
note
|
||||
description: "Summary description for {ROUTED_APPLICATION_HELPER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
ROUTED_APPLICATION_HELPER
|
||||
|
||||
inherit
|
||||
ANY
|
||||
|
||||
feature -- Helper
|
||||
|
||||
execute_content_type_not_allowed (req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER; a_content_types: detachable ARRAY [STRING]; a_uri_formats: detachable ARRAY [STRING])
|
||||
local
|
||||
s, uri_s: detachable STRING
|
||||
i, n: INTEGER
|
||||
h: EWF_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_status ({HTTP_STATUS_CODE}.unsupported_media_type)
|
||||
h.put_content_type_text_plain
|
||||
|
||||
if a_content_types /= Void then
|
||||
create s.make (10)
|
||||
from
|
||||
i := a_content_types.lower
|
||||
n := a_content_types.upper
|
||||
until
|
||||
i > n
|
||||
loop
|
||||
s.append_string (a_content_types[i])
|
||||
if i < n then
|
||||
s.append_character (',')
|
||||
s.append_character (' ')
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
h.put_header_key_value ("Accept", s)
|
||||
end
|
||||
if a_uri_formats /= Void then
|
||||
create uri_s.make (10)
|
||||
from
|
||||
i := a_uri_formats.lower
|
||||
n := a_uri_formats.upper
|
||||
until
|
||||
i > n
|
||||
loop
|
||||
uri_s.append_string (a_uri_formats[i])
|
||||
if i < n then
|
||||
uri_s.append_character (',')
|
||||
uri_s.append_character (' ')
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.unsupported_media_type)
|
||||
res.write_headers_string (h.string)
|
||||
if s /= Void then
|
||||
res.write_string ("Unsupported request content-type, Accept: " + s + "%N")
|
||||
end
|
||||
if uri_s /= Void then
|
||||
res.write_string ("Unsupported request format from the URI: " + uri_s + "%N")
|
||||
end
|
||||
end
|
||||
|
||||
execute_request_method_not_allowed (req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER; a_methods: ITERABLE [STRING])
|
||||
local
|
||||
s: STRING
|
||||
do
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.method_not_allowed)
|
||||
create s.make (25)
|
||||
across
|
||||
a_methods as c
|
||||
loop
|
||||
if not s.is_empty then
|
||||
s.append_character (',')
|
||||
s.append_character (' ')
|
||||
end
|
||||
s.append_string (c.item)
|
||||
end
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.method_not_allowed)
|
||||
res.write_header ({HTTP_STATUS_CODE}.method_not_allowed, <<
|
||||
["Content-Type", {HTTP_CONSTANTS}.plain_text],
|
||||
["Allow", s]
|
||||
>>)
|
||||
res.write_string ("Unsupported request method, Allow: " + s + "%N")
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, 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
|
||||
Reference in New Issue
Block a user