merged from upstream
This commit is contained in:
@@ -9,6 +9,9 @@ deferred class
|
||||
|
||||
inherit
|
||||
WSF_ROUTER_MAPPING
|
||||
redefine
|
||||
debug_output
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
@@ -17,6 +20,14 @@ feature -- Access
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
debug_output: STRING
|
||||
-- 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"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
@@ -17,8 +17,11 @@ inherit
|
||||
on_mapped
|
||||
end
|
||||
|
||||
WSF_SELF_DOCUMENTED_HANDLER
|
||||
|
||||
create
|
||||
make
|
||||
make,
|
||||
make_hidden
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
@@ -27,10 +30,28 @@ feature {NONE} -- Initialization
|
||||
router := a_router
|
||||
end
|
||||
|
||||
make_hidden (a_router: WSF_ROUTER)
|
||||
do
|
||||
make (a_router)
|
||||
is_hidden := True
|
||||
end
|
||||
|
||||
router: WSF_ROUTER
|
||||
|
||||
resource: detachable STRING
|
||||
|
||||
is_hidden: BOOLEAN
|
||||
-- Current mapped handler should be hidden from self documentation
|
||||
|
||||
feature -- Documentation
|
||||
|
||||
mapping_documentation (m: WSF_ROUTER_MAPPING): WSF_ROUTER_MAPPING_DOCUMENTATION
|
||||
do
|
||||
create Result.make (m)
|
||||
Result.set_is_hidden (is_hidden)
|
||||
Result.add_description ("Self generated documentation based on the router's setup")
|
||||
end
|
||||
|
||||
feature {WSF_ROUTER} -- Mapping
|
||||
|
||||
on_mapped (a_mapping: WSF_ROUTER_MAPPING; a_rqst_methods: detachable WSF_ROUTER_METHODS)
|
||||
|
||||
@@ -195,7 +195,6 @@ feature {WSF_RESPONSE} -- Output
|
||||
local
|
||||
l_url: detachable STRING_8
|
||||
l_base_url: detachable READABLE_STRING_8
|
||||
hdl: WSF_HANDLER
|
||||
l_doc: detachable WSF_ROUTER_MAPPING_DOCUMENTATION
|
||||
do
|
||||
if attached {WSF_SELF_DOCUMENTED_ROUTER_MAPPING} m as l_doc_mapping then
|
||||
@@ -223,21 +222,24 @@ feature {WSF_RESPONSE} -- Output
|
||||
s.append ("</code>")
|
||||
|
||||
if meths /= Void then
|
||||
s.append (" [ ")
|
||||
s.append (" [")
|
||||
across
|
||||
meths as rq
|
||||
loop
|
||||
s.append_character (' ')
|
||||
if l_url /= Void and then rq.item.is_case_insensitive_equal ("GET") then
|
||||
s.append ("<a href=%"" + l_base_url + l_url + "%">" + rq.item + "</a>")
|
||||
else
|
||||
s.append (rq.item)
|
||||
end
|
||||
if not rq.is_last then
|
||||
s.append (",")
|
||||
end
|
||||
s.append (" ")
|
||||
s.append_character (',')
|
||||
end
|
||||
s.append ("]")
|
||||
if s[s.count] = ',' then
|
||||
s.put (' ', s.count)
|
||||
else
|
||||
s.append_character (' ')
|
||||
end
|
||||
s.append_character (']')
|
||||
end
|
||||
|
||||
s.append (" <em class=%"mappingdoc%">" + html_encoder.encoded_string (m.description) + "</em> ")
|
||||
|
||||
93
library/server/wsf/router/filter/wsf_logging_filter.e
Normal file
93
library/server/wsf/router/filter/wsf_logging_filter.e
Normal file
@@ -0,0 +1,93 @@
|
||||
note
|
||||
description: "Logging filter."
|
||||
author: "Olivier Ligot"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_LOGGING_FILTER
|
||||
|
||||
inherit
|
||||
WSF_FILTER
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
create
|
||||
default_create,
|
||||
make_with_output
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
output := io.output
|
||||
end
|
||||
|
||||
make_with_output (a_output: like output)
|
||||
-- Create Current with `a_output' as `output'
|
||||
require
|
||||
a_output_opened: a_output.is_open_read
|
||||
do
|
||||
default_create
|
||||
output := a_output
|
||||
end
|
||||
|
||||
output: FILE
|
||||
-- Output file
|
||||
--| Could be stdout, or a file...
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute the filter
|
||||
local
|
||||
l_date: DATE_TIME
|
||||
s: STRING
|
||||
do
|
||||
create s.make (64)
|
||||
s.append (req.remote_addr)
|
||||
s.append (" - - [")
|
||||
create l_date.make_now_utc
|
||||
s.append (l_date.formatted_out (Date_time_format))
|
||||
s.append (" GMT] %"")
|
||||
s.append (req.request_method)
|
||||
s.append_character (' ')
|
||||
s.append (req.request_uri)
|
||||
s.append_character (' ')
|
||||
s.append ({HTTP_CONSTANTS}.http_version_1_1)
|
||||
s.append_character ('%"')
|
||||
s.append_character (' ')
|
||||
s.append_integer (res.status_code)
|
||||
s.append_character (' ')
|
||||
s.append_natural_64 (res.transfered_content_length)
|
||||
s.append_character (' ')
|
||||
if attached req.http_referer as r then
|
||||
s.append_character ('%"')
|
||||
s.append_character ('%"')
|
||||
s.append (r)
|
||||
s.append_character (' ')
|
||||
end
|
||||
|
||||
if attached req.http_user_agent as ua then
|
||||
s.append_character ('%"')
|
||||
s.append (ua)
|
||||
s.append_character ('%"')
|
||||
else
|
||||
s.append_character ('-')
|
||||
end
|
||||
|
||||
output.put_string (s)
|
||||
output.put_new_line
|
||||
execute_next (req, res)
|
||||
end
|
||||
|
||||
feature -- Constants
|
||||
|
||||
Date_time_format: STRING = "[0]dd/[0]mm/yyyy [0]hh:[0]mi:[0]ss"
|
||||
|
||||
note
|
||||
copyright: "2011-2012, Olivier Ligot, Jocelyn Fiat and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
@@ -10,6 +10,8 @@ class
|
||||
inherit
|
||||
WSF_ROUTER_MAPPING
|
||||
|
||||
WSF_SELF_DOCUMENTED_ROUTER_MAPPING
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ inherit
|
||||
|
||||
WSF_SELF_DOCUMENTED_ROUTER_MAPPING
|
||||
|
||||
DEBUG_OUTPUT
|
||||
|
||||
create
|
||||
make,
|
||||
make_from_template
|
||||
@@ -47,14 +45,6 @@ feature -- Documentation
|
||||
|
||||
description: STRING_32 = "Match-URI-Template"
|
||||
|
||||
feature -- Status report
|
||||
|
||||
debug_output: STRING
|
||||
-- String that should be displayed in debugger to represent `Current'.
|
||||
do
|
||||
Result := "URI-template: " + template.template
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_handler (h: like handler)
|
||||
|
||||
@@ -11,8 +11,9 @@ inherit
|
||||
WSF_ROUTER_CONTEXT_MAPPING [C]
|
||||
|
||||
WSF_SELF_DOCUMENTED_ROUTER_MAPPING
|
||||
|
||||
DEBUG_OUTPUT
|
||||
undefine
|
||||
debug_output
|
||||
end
|
||||
|
||||
create
|
||||
make,
|
||||
@@ -45,15 +46,7 @@ feature -- Access
|
||||
|
||||
feature -- Documentation
|
||||
|
||||
description: STRING_32 = "Is-URI"
|
||||
|
||||
feature -- Status report
|
||||
|
||||
debug_output: STRING
|
||||
-- String that should be displayed in debugger to represent `Current'.
|
||||
do
|
||||
Result := "URI-template: " + template.template
|
||||
end
|
||||
description: STRING_32 = "Match-URI-Template"
|
||||
|
||||
feature -- Element change
|
||||
|
||||
|
||||
@@ -47,7 +47,11 @@ feature -- Execution
|
||||
|
||||
execute_default (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Default procedure
|
||||
deferred
|
||||
local
|
||||
not_found: WSF_NOT_FOUND_RESPONSE
|
||||
do
|
||||
create not_found.make (req)
|
||||
res.send (not_found)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
note
|
||||
description: "Summary description for {EWF_ROUTER}."
|
||||
author: ""
|
||||
description: "[
|
||||
URL dispatching of request
|
||||
|
||||
Map a route to an handler according to the request method and path
|
||||
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
@@ -10,6 +14,8 @@ class
|
||||
inherit
|
||||
ITERABLE [WSF_ROUTER_ITEM]
|
||||
|
||||
WSF_REQUEST_EXPORTER
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_base_url
|
||||
@@ -53,8 +59,15 @@ feature -- Mapping
|
||||
map_with_request_methods (a_mapping: WSF_ROUTER_MAPPING; rqst_methods: detachable WSF_ROUTER_METHODS)
|
||||
-- Map `a_mapping' for request methods `rqst_methods'
|
||||
do
|
||||
if attached rqst_methods as l_rm and then l_rm.has ({HTTP_REQUEST_METHODS}.method_get) then
|
||||
l_rm.enable_head
|
||||
debug ("router")
|
||||
-- Display conflict in mapping
|
||||
if has_item_associated_with_resource (a_mapping.associated_resource, rqst_methods) then
|
||||
io.error.put_string ("Mapping: " + a_mapping.debug_output + ": conflict with existing mapping")
|
||||
if attached item_associated_with_resource (a_mapping.associated_resource, rqst_methods) as l_conflicted then
|
||||
io.error.put_string (": " + l_conflicted.debug_output)
|
||||
end
|
||||
io.error.put_string ("%N")
|
||||
end
|
||||
end
|
||||
mappings.extend (create {WSF_ROUTER_ITEM}.make_with_request_methods (a_mapping, rqst_methods))
|
||||
a_mapping.handler.on_mapped (a_mapping, rqst_methods)
|
||||
@@ -95,10 +108,28 @@ feature -- Access
|
||||
-- And return the associated handler if mapping found and handler executed.
|
||||
local
|
||||
l_req_method: READABLE_STRING_8
|
||||
head_res: WSF_HEAD_RESPONSE_WRAPPER
|
||||
do
|
||||
l_req_method := request_method (req)
|
||||
is_dispatched := False
|
||||
Result := dispatch_and_return_handler_for_request_method (req, res, l_req_method)
|
||||
if Result = Void and l_req_method = {HTTP_REQUEST_METHODS}.method_head then
|
||||
check is_not_dispatched: not is_dispatched end
|
||||
create head_res.make_from_response (res)
|
||||
req.set_request_method ({HTTP_REQUEST_METHODS}.method_GET)
|
||||
Result := dispatch_and_return_handler_for_request_method (req, head_res, {HTTP_REQUEST_METHODS}.method_GET)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Dispatch implementation
|
||||
|
||||
dispatch_and_return_handler_for_request_method (req: WSF_REQUEST; res: WSF_RESPONSE; a_request_method: READABLE_STRING_8): detachable WSF_HANDLER
|
||||
-- Dispatch request `req' among the `mappings'
|
||||
-- And return the associated handler if mapping found and handler executed.
|
||||
local
|
||||
m: WSF_ROUTER_MAPPING
|
||||
do
|
||||
is_dispatched := False
|
||||
l_req_method := request_method (req)
|
||||
|
||||
across
|
||||
mappings as c
|
||||
@@ -106,7 +137,7 @@ feature -- Access
|
||||
Result /= Void
|
||||
loop
|
||||
if attached c.item as l_info then
|
||||
if is_matching_request_methods (l_req_method, l_info.request_methods) then
|
||||
if is_matching_request_methods (a_request_method, l_info.request_methods) then
|
||||
m := l_info.mapping
|
||||
if attached m.routed_handler (req, res, Current) as r then
|
||||
is_dispatched := True
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
note
|
||||
description: "Summary description for {WSF_ROUTER_ITEM}."
|
||||
author: ""
|
||||
description: "[
|
||||
Entry of WSF_ROUTER
|
||||
It contains
|
||||
- mapping
|
||||
- request methods
|
||||
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
@@ -38,11 +43,7 @@ feature -- Status report
|
||||
debug_output: STRING
|
||||
-- String that should be displayed in debugger to represent `Current'.
|
||||
do
|
||||
if attached {DEBUG_OUTPUT} mapping as d then
|
||||
create Result.make_from_string (d.debug_output)
|
||||
else
|
||||
create Result.make_from_string (mapping.generator)
|
||||
end
|
||||
create Result.make_from_string (mapping.debug_output)
|
||||
if attached request_methods as mtds then
|
||||
Result.append_string (" [ ")
|
||||
across
|
||||
@@ -66,4 +67,15 @@ feature -- Change
|
||||
invariant
|
||||
mapping_attached: mapping /= Void
|
||||
|
||||
note
|
||||
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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
|
||||
|
||||
@@ -7,6 +7,9 @@ note
|
||||
deferred class
|
||||
WSF_ROUTER_MAPPING
|
||||
|
||||
inherit
|
||||
DEBUG_OUTPUT
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_resource: READABLE_STRING_8; h: like handler)
|
||||
@@ -33,6 +36,14 @@ feature -- Documentation
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
debug_output: STRING
|
||||
-- String that should be displayed in debugger to represent `Current'.
|
||||
do
|
||||
Result := description.as_string_8 + " : " + associated_resource
|
||||
end
|
||||
|
||||
feature -- Status
|
||||
|
||||
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER
|
||||
|
||||
Reference in New Issue
Block a user