From 1a88388ffeb354c7c8caa50a29882e1363cc310a Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Fri, 25 Nov 2011 16:24:55 +0100 Subject: [PATCH] added "redirect" helper feature to WSF_RESPONSE --- library/server/wsf/src/wsf_response.e | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/library/server/wsf/src/wsf_response.e b/library/server/wsf/src/wsf_response.e index 1628a2a3..c88ccbe4 100644 --- a/library/server/wsf/src/wsf_response.e +++ b/library/server/wsf/src/wsf_response.e @@ -146,6 +146,33 @@ feature -- Output operation wgi_response.flush end +feature -- Helper + + redirect_now_with_custom_status_code (a_url: READABLE_STRING_8; a_status_code: INTEGER) + -- Redirect to the given url `a_url' and precise custom `a_status_code' + -- Please see http://www.faqs.org/rfcs/rfc2616 to use proper status code. + require + header_not_committed: not header_committed + local + h: HTTP_HEADER + do + if header_committed then + write_string ("Headers already sent.%NCannot redirect, for now please follow this link instead%N") + else + create h.make_with_count (1) + h.put_location (a_url) + set_status_code (a_status_code) + end + end + + redirect_now (a_url: READABLE_STRING_8) + -- Redirect to the given url `a_url' + require + header_not_committed: not header_committed + do + redirect_now_with_custom_status_code (a_url, {HTTP_STATUS_CODE}.moved_permanently) + end + note copyright: "2011-2011, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"