Conflicts:
	library/server/wsf/src/wsf_request.e
This commit is contained in:
Jocelyn Fiat
2011-10-27 15:49:12 +02:00
172 changed files with 34380 additions and 60 deletions

View File

@@ -156,7 +156,10 @@ feature -- Method Extension Method
end
feature -- Handle responses
-- TODO Handle Content negotiation.
-- The option : Server-driven negotiation: uses request headers to select a variant
-- More info : http://www.w3.org/Protocols/rfc2616/rfc2616-sec12.html#sec12
supported_content_types: detachable ARRAY [READABLE_STRING_8]
-- Supported content types
-- Can be redefined
@@ -170,11 +173,7 @@ feature -- Handle responses
do
create h.make
h.put_status ({HTTP_STATUS_CODE}.bad_request)
if attached ctx.request_content_type (supported_content_types) as l_content_type then
h.put_content_type (l_content_type)
else
h.put_content_type ("*/*")
end
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.bad_request)
@@ -182,19 +181,28 @@ feature -- Handle responses
res.write_string (a_description)
end
handle_precondition_fail_response (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE )
local
h : WSF_HEADER
do
create h.make
h.put_status ({HTTP_STATUS_CODE}.precondition_failed)
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.precondition_failed)
res.write_headers_string (h.string)
res.write_string (a_description)
end
handle_internal_server_error (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE )
local
h : WSF_HEADER
do
create h.make
h.put_status ({HTTP_STATUS_CODE}.internal_server_error)
if attached ctx.request_content_type (supported_content_types) as l_content_type then
h.put_content_type (l_content_type)
else
h.put_content_type ("*/*")
--| FIXME: I guess it should be plain/text ,
--| */* sounds more for Accept header in request
end
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.internal_server_error)
@@ -208,11 +216,7 @@ feature -- Handle responses
do
create h.make
h.put_status ({HTTP_STATUS_CODE}.not_implemented)
if attached ctx.request_content_type (supported_content_types) as l_content_type then
h.put_content_type (l_content_type)
else
h.put_content_type ("*/*")
end
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.not_implemented)
@@ -220,17 +224,27 @@ feature -- Handle responses
res.write_string (a_description)
end
handle_method_not_allowed_response (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : WSF_HEADER
do
create h.make
h.put_status ({HTTP_STATUS_CODE}.method_not_allowed)
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.method_not_allowed)
res.write_headers_string (h.string)
res.write_string (a_description)
end
handle_resource_not_found_response (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : WSF_HEADER
do
create h.make
h.put_status ({HTTP_STATUS_CODE}.not_found)
if attached ctx.request_content_type (supported_content_types) as l_content_type then
h.put_content_type (l_content_type)
else
h.put_content_type ("*/*")
end
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.not_found)
@@ -238,6 +252,37 @@ feature -- Handle responses
res.write_string (a_description)
end
handle_resource_not_modified_response (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : WSF_HEADER
do
res.flush
create h.make
h.put_status ({HTTP_STATUS_CODE}.not_modified)
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.not_modified)
res.write_headers_string (h.string)
res.write_string (a_description)
end
handle_resource_conflict_response (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : WSF_HEADER
do
create h.make
h.put_status ({HTTP_STATUS_CODE}.conflict)
h.put_content_type_application_json
h.put_content_length (a_description.count)
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.conflict)
res.write_headers_string (h.string)
res.write_string (a_description)
end
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"