Added WSF_DEFAULT_*_RESPONSE
Fixed the method not allowed by setting the Allow: header
This commit is contained in:
@@ -48,22 +48,9 @@ feature -- Execution
|
||||
execute_default (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Default procedure
|
||||
local
|
||||
msg: WSF_RESPONSE_MESSAGE
|
||||
not_found: WSF_NOT_FOUND_RESPONSE
|
||||
not_allowed: WSF_METHOD_NOT_ALLOWED_RESPONSE
|
||||
trace: WSF_TRACE_RESPONSE
|
||||
msg: WSF_DEFAULT_ROUTER_RESPONSE
|
||||
do
|
||||
if req.is_request_method ({HTTP_REQUEST_METHODS}.method_trace) then
|
||||
create trace.make (req)
|
||||
msg := trace
|
||||
elseif attached router.allowed_methods_for_request (req) as mtds and then not mtds.is_empty then
|
||||
create not_allowed.make (req)
|
||||
not_allowed.set_suggested_methods (mtds)
|
||||
msg := not_allowed
|
||||
else
|
||||
create not_found.make (req)
|
||||
msg := not_found
|
||||
end
|
||||
create msg.make_with_router (req, router)
|
||||
res.send (msg)
|
||||
end
|
||||
|
||||
|
||||
53
library/server/wsf/src/response/wsf_default_response.e
Normal file
53
library/server/wsf/src/response/wsf_default_response.e
Normal file
@@ -0,0 +1,53 @@
|
||||
note
|
||||
description: "Summary description for {WSF_DEFAULT_RESPONSE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_DEFAULT_RESPONSE
|
||||
|
||||
inherit
|
||||
WSF_RESPONSE_MESSAGE
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (req: WSF_REQUEST)
|
||||
-- Initialize Current with request `req'
|
||||
do
|
||||
request := req
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
request: WSF_REQUEST
|
||||
-- Associated request.
|
||||
|
||||
feature {WSF_RESPONSE} -- Output
|
||||
|
||||
send_to (res: WSF_RESPONSE)
|
||||
-- Send Current message to `res'
|
||||
--
|
||||
-- This feature should be called via `{WSF_RESPONSE}.send (obj)'
|
||||
-- where `obj' is the current object
|
||||
local
|
||||
msg: WSF_RESPONSE_MESSAGE
|
||||
req: like request
|
||||
not_found: WSF_NOT_FOUND_RESPONSE
|
||||
trace: WSF_TRACE_RESPONSE
|
||||
do
|
||||
req := request
|
||||
if req.is_request_method ({HTTP_REQUEST_METHODS}.method_trace) then
|
||||
create trace.make (req)
|
||||
msg := trace
|
||||
else
|
||||
create not_found.make (req)
|
||||
msg := not_found
|
||||
end
|
||||
res.send (msg)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,63 @@
|
||||
note
|
||||
description: "Summary description for {WSF_DEFAULT_ROUTER_RESPONSE}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_DEFAULT_ROUTER_RESPONSE
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_RESPONSE
|
||||
redefine
|
||||
send_to
|
||||
end
|
||||
|
||||
create
|
||||
make_with_router
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_with_router (req: WSF_REQUEST; a_router: like router)
|
||||
-- Initialize Current with request `req' and router `a_router'
|
||||
-- Initialize Current with request `req'
|
||||
do
|
||||
router := a_router
|
||||
make (req)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
router: WSF_ROUTER
|
||||
-- Associated router.
|
||||
|
||||
feature {WSF_RESPONSE} -- Output
|
||||
|
||||
send_to (res: WSF_RESPONSE)
|
||||
-- Send Current message to `res'
|
||||
--
|
||||
-- This feature should be called via `{WSF_RESPONSE}.send (obj)'
|
||||
-- where `obj' is the current object
|
||||
local
|
||||
msg: WSF_RESPONSE_MESSAGE
|
||||
req: like request
|
||||
not_found: WSF_NOT_FOUND_RESPONSE
|
||||
not_allowed: WSF_METHOD_NOT_ALLOWED_RESPONSE
|
||||
trace: WSF_TRACE_RESPONSE
|
||||
do
|
||||
req := request
|
||||
if req.is_request_method ({HTTP_REQUEST_METHODS}.method_trace) then
|
||||
create trace.make (req)
|
||||
msg := trace
|
||||
elseif attached router.allowed_methods_for_request (req) as mtds and then not mtds.is_empty then
|
||||
create not_allowed.make (req)
|
||||
not_allowed.set_suggested_methods (mtds)
|
||||
msg := not_allowed
|
||||
else
|
||||
create not_found.make (req)
|
||||
|
||||
msg := not_found
|
||||
end
|
||||
res.send (msg)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -54,6 +54,11 @@ feature {WSF_RESPONSE} -- Output
|
||||
do
|
||||
h := header
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.method_not_allowed)
|
||||
|
||||
if attached suggested_methods as lst and then not lst.is_empty then
|
||||
h.put_allow (lst)
|
||||
end
|
||||
|
||||
s := "Not allowed"
|
||||
|
||||
if request.is_content_type_accepted ({HTTP_MIME_TYPES}.text_html) then
|
||||
@@ -119,6 +124,7 @@ feature {WSF_RESPONSE} -- Output
|
||||
end
|
||||
h.put_content_type_text_plain
|
||||
end
|
||||
|
||||
h.put_content_length (s.count)
|
||||
res.put_header_text (h.string)
|
||||
res.put_string (s)
|
||||
|
||||
Reference in New Issue
Block a user