Improved comment in WSF_RESPONSE.put_response (..)

Added WSF_REDIRECTION_RESPONSE class
This commit is contained in:
Jocelyn Fiat
2012-03-19 12:32:12 +01:00
parent 487487ad44
commit 4906345a62
2 changed files with 121 additions and 5 deletions

View File

@@ -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

View File

@@ -185,15 +185,20 @@ feature -- Output operation
wgi_response.flush wgi_response.flush
end end
feature -- Helper feature -- Response object
put_response (obj: WSF_RESPONSE_MESSAGE) 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 require
not header_committed header_not_committed: not header_committed
not status_is_set status_not_committed: not status_committed
not message_committed no_message_committed: not message_committed
do do
obj.send_to (Current) obj.send_to (Current)
ensure
status_committed: status_committed
header_committed: header_committed
end end
feature -- Redirect 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_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 -- 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. -- 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 require
header_not_committed: not header_committed header_not_committed: not header_committed
local local