From 4906345a62f17f5fadee6c5e0db964ca0a1f855b Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 19 Mar 2012 12:32:12 +0100 Subject: [PATCH] Improved comment in WSF_RESPONSE.put_response (..) Added WSF_REDIRECTION_RESPONSE class --- .../src/response/wsf_redirection_response.e | 111 ++++++++++++++++++ library/server/wsf/src/wsf_response.e | 15 ++- 2 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 library/server/wsf/src/response/wsf_redirection_response.e diff --git a/library/server/wsf/src/response/wsf_redirection_response.e b/library/server/wsf/src/response/wsf_redirection_response.e new file mode 100644 index 00000000..80da1a9f --- /dev/null +++ b/library/server/wsf/src/response/wsf_redirection_response.e @@ -0,0 +1,111 @@ +note + description: "[ + This class is used to send a redirection + ]" + date: "$Date$" + revision: "$Revision$" + +class + WSF_REDIRECTION_RESPONSE + +inherit + WSF_RESPONSE_MESSAGE + +create + make + +feature {NONE} -- Initialization + + make (a_url_location: like url_location) + do + status_code := {HTTP_STATUS_CODE}.temp_redirect + url_location := a_url_location + create header.make + end + +feature -- Status + + status_code: INTEGER + +feature -- Header + + header: HTTP_HEADER + -- Response' header + + url_location: STRING_8 + -- New url location after redirection + + content: detachable READABLE_STRING_8 + -- Optional content + + content_type: detachable READABLE_STRING_8 + -- Content type associated with `content' + +feature -- Element change + + set_status_code (c: like status_code) + -- Set the status code + do + status_code := c + end + + set_url_location (a_url_location: like url_location) + -- Set `url_location' to `a_url_location' + do + url_location := a_url_location + end + + set_content (a_content: attached like content; a_content_type: attached like content_type) + -- Set `a_content' of type `a_content_type' + do + content := a_content + content_type := a_content_type + end + + remove_content + -- Remove content data + do + content := Void + content_type := Void + end + +feature -- Output + + send_to (res: WSF_RESPONSE) + local + b: like content + h: like header + do + h := header + b := content + res.set_status_code (status_code) + + h.put_location (url_location) + + if b /= Void then + if not h.has_content_length then + h.put_content_length (b.count) + end + if attached content_type as t then + h.put_content_type (t) + elseif not h.has_content_type then + h.put_content_type_text_plain + end + end + res.put_header_text (h.string) + if b /= Void then + res.put_string (b) + end + end + +note + copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, 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 diff --git a/library/server/wsf/src/wsf_response.e b/library/server/wsf/src/wsf_response.e index 320ab09c..8214ce7f 100644 --- a/library/server/wsf/src/wsf_response.e +++ b/library/server/wsf/src/wsf_response.e @@ -185,15 +185,20 @@ feature -- Output operation wgi_response.flush end -feature -- Helper +feature -- Response object put_response (obj: WSF_RESPONSE_MESSAGE) + -- Set `obj' as the whole response to the client + --| `obj' is responsible to sent the status code, the header and the content require - not header_committed - not status_is_set - not message_committed + header_not_committed: not header_committed + status_not_committed: not status_committed + no_message_committed: not message_committed do obj.send_to (Current) + ensure + status_committed: status_committed + header_committed: header_committed end feature -- Redirect @@ -201,7 +206,7 @@ feature -- Redirect redirect_now_custom (a_url: READABLE_STRING_8; a_status_code: INTEGER; a_header: detachable HTTP_HEADER; a_content: detachable TUPLE [body: READABLE_STRING_8; type: READABLE_STRING_8]) -- Redirect to the given url `a_url' and precise custom `a_status_code', custom header and content -- Please see http://www.faqs.org/rfcs/rfc2616 to use proper status code. - -- if `a_status_code' is 0, use the default {HTTP_STATUS_CODE}.moved_permanently + -- if `a_status_code' is 0, use the default {HTTP_STATUS_CODE}.temp_redirect require header_not_committed: not header_committed local