- (WGI|WSF)_RESPONSE(*) renamed write_headers_string as write_header_text
- HTTP_HEADER.string does not have the ending CRLFCRLF .. but just CRLF - WGI_RESPONSE.write_header_text has the responsibility to handle the last blank line CRLF (separating the header from the message) - HTTP_HEADER.string does not set anymore a default content type as text/html - added WGI_RESPONSE.write_header_lines (ITERABLE [TUPLE [name,value: READABLE_STRING_8]] mainly as an helper method, this way the WGI user does not have to know about the CRLF end of line
This commit is contained in:
@@ -158,7 +158,7 @@ feature -- Output
|
|||||||
send (buf: WSF_RESPONSE)
|
send (buf: WSF_RESPONSE)
|
||||||
do
|
do
|
||||||
buf.set_status_code (200)
|
buf.set_status_code (200)
|
||||||
buf.write_headers_string (header_string)
|
buf.write_header_text (header_string)
|
||||||
buf.write_string (message_string)
|
buf.write_string (message_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ feature -- Output
|
|||||||
do
|
do
|
||||||
compute
|
compute
|
||||||
res.set_status_code (200)
|
res.set_status_code (200)
|
||||||
res.write_headers_string (headers_string)
|
res.write_header_text (headers_string)
|
||||||
if attached message as m then
|
if attached message as m then
|
||||||
res.write_string (m)
|
res.write_string (m)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ feature -- Execution
|
|||||||
end
|
end
|
||||||
if not s.is_empty then
|
if not s.is_empty then
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (s)
|
res.write_string (s)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ feature -- Execution
|
|||||||
end
|
end
|
||||||
|
|
||||||
res.set_status_code (200)
|
res.set_status_code (200)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (s)
|
res.write_string (s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ feature -- Execution
|
|||||||
s.append ("You are being redirected to <a href=%"" + l_redir_url + "%">/doc</a> in 2 seconds ...%N")
|
s.append ("You are being redirected to <a href=%"" + l_redir_url + "%">/doc</a> in 2 seconds ...%N")
|
||||||
h.put_content_length (s.count)
|
h.put_content_length (s.count)
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.temp_redirect)
|
res.set_status_code ({HTTP_STATUS_CODE}.temp_redirect)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (s)
|
res.write_string (s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ feature -- Execution
|
|||||||
h.put_transfer_encoding_chunked
|
h.put_transfer_encoding_chunked
|
||||||
-- h.put_content_length (0)
|
-- h.put_content_length (0)
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.moved_permanently)
|
res.set_status_code ({HTTP_STATUS_CODE}.moved_permanently)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
|
|
||||||
from
|
from
|
||||||
create e
|
create e
|
||||||
@@ -202,7 +202,7 @@ feature -- Execution
|
|||||||
h.put_content_type (l_response_content_type)
|
h.put_content_type (l_response_content_type)
|
||||||
h.put_content_length (l_body.count)
|
h.put_content_length (l_body.count)
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (l_body)
|
res.write_string (l_body)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ feature -- HTTP Methods
|
|||||||
end
|
end
|
||||||
h.add_header ("etag:" + etag_utils.md5_digest (l_order.out))
|
h.add_header ("etag:" + etag_utils.md5_digest (l_order.out))
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (l_msg)
|
res.write_string (l_msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -171,7 +171,7 @@ feature -- HTTP Methods
|
|||||||
if attached {JSON_VALUE} json.value (l_order) as jv then
|
if attached {JSON_VALUE} json.value (l_order) as jv then
|
||||||
h.put_content_length (jv.representation.count)
|
h.put_content_length (jv.representation.count)
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (jv.representation)
|
res.write_string (jv.representation)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -214,7 +214,7 @@ feature -- HTTP Methods
|
|||||||
h.put_utc_date (time)
|
h.put_utc_date (time)
|
||||||
end
|
end
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.no_content)
|
res.set_status_code ({HTTP_STATUS_CODE}.no_content)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
end
|
end
|
||||||
|
|
||||||
do_post (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
|
do_post (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
@@ -264,7 +264,7 @@ feature -- HTTP Methods
|
|||||||
h.put_utc_date (time)
|
h.put_utc_date (time)
|
||||||
end
|
end
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.created)
|
res.set_status_code ({HTTP_STATUS_CODE}.created)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (l_msg)
|
res.write_string (l_msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ feature -- Execution
|
|||||||
h.put_content_length (l_description.count)
|
h.put_content_length (l_description.count)
|
||||||
h.put_current_date
|
h.put_current_date
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.method_not_allowed)
|
res.set_status_code ({HTTP_STATUS_CODE}.method_not_allowed)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (l_description)
|
res.write_string (l_description)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -66,11 +66,9 @@ feature -- Access
|
|||||||
local
|
local
|
||||||
l_headers: like headers
|
l_headers: like headers
|
||||||
do
|
do
|
||||||
create Result.make (32)
|
|
||||||
l_headers := headers
|
l_headers := headers
|
||||||
if l_headers.is_empty then
|
if not l_headers.is_empty then
|
||||||
put_content_type_text_html -- See if this make sense to define a default content-type
|
create Result.make (32)
|
||||||
else
|
|
||||||
from
|
from
|
||||||
l_headers.start
|
l_headers.start
|
||||||
until
|
until
|
||||||
@@ -79,8 +77,12 @@ feature -- Access
|
|||||||
append_line_to (l_headers.item, Result)
|
append_line_to (l_headers.item, Result)
|
||||||
l_headers.forth
|
l_headers.forth
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
create Result.make_empty
|
||||||
end
|
end
|
||||||
append_end_of_line_to (Result)
|
ensure
|
||||||
|
result_has_ending_cr_lf: Result.count >= 2 implies Result.substring (Result.count - 2, Result.count).same_string ("%R%N")
|
||||||
|
result_has_single_ending_cr_lf: Result.count >= 4 implies not Result.substring (Result.count - 4, Result.count).same_string ("%R%N%R%N")
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Header change: general
|
feature -- Header change: general
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
execute (req: WGI_REQUEST; res: WGI_RESPONSE)
|
execute (req: WGI_REQUEST; res: WGI_RESPONSE)
|
||||||
do
|
do
|
||||||
res.write_header (200, <<["Content-Type", "text/plain"]>>)
|
res.set_status_code (200)
|
||||||
|
res.write_header_lines (<<["Content-Type: text/plain"]>>)
|
||||||
res.write_string ("Hello World!%N")
|
res.write_string ("Hello World!%N")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,22 @@ feature -- Status setting
|
|||||||
|
|
||||||
feature -- Header output operation
|
feature -- Header output operation
|
||||||
|
|
||||||
write_headers (a_headers: READABLE_STRING_8)
|
write_header_text (a_text: READABLE_STRING_8)
|
||||||
|
-- Write http header string `a_text'
|
||||||
|
-- It should not contain the ending CR LF CR LF
|
||||||
|
-- since it is the duty of `write_header_text' to write it.
|
||||||
|
require
|
||||||
|
a_text_does_not_has_ending_crlf_crlf: a_text.count > 4 implies not a_text.substring (a_text.count - 4, a_text.count).same_string ("%R%N%R%N")
|
||||||
|
status_set: status_is_set
|
||||||
|
header_not_committed: not header_committed
|
||||||
|
deferred
|
||||||
|
ensure
|
||||||
|
status_set: status_is_set
|
||||||
|
header_committed: header_committed
|
||||||
|
message_writable: message_writable
|
||||||
|
end
|
||||||
|
|
||||||
|
write_header_lines (a_lines: ITERABLE [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]])
|
||||||
require
|
require
|
||||||
status_set: status_is_set
|
status_set: status_is_set
|
||||||
header_not_committed: not header_committed
|
header_not_committed: not header_committed
|
||||||
|
|||||||
@@ -75,12 +75,31 @@ feature -- Status setting
|
|||||||
|
|
||||||
feature -- Header output operation
|
feature -- Header output operation
|
||||||
|
|
||||||
write_headers (a_headers: READABLE_STRING_8)
|
write_header_text (a_text: READABLE_STRING_8)
|
||||||
do
|
do
|
||||||
write (a_headers)
|
write (a_text)
|
||||||
|
write (crlf)
|
||||||
header_committed := True
|
header_committed := True
|
||||||
end
|
end
|
||||||
|
|
||||||
|
write_header_lines (a_lines: ITERABLE [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]])
|
||||||
|
local
|
||||||
|
h: STRING_8
|
||||||
|
do
|
||||||
|
create h.make (256)
|
||||||
|
across
|
||||||
|
a_lines as c
|
||||||
|
loop
|
||||||
|
h.append (c.item.name)
|
||||||
|
h.append_character (':')
|
||||||
|
h.append_character (' ')
|
||||||
|
h.append (c.item.value)
|
||||||
|
h.append_character ('%R')
|
||||||
|
h.append_character ('%N')
|
||||||
|
end
|
||||||
|
write_header_text (h)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Output operation
|
feature -- Output operation
|
||||||
|
|
||||||
write_string (s: READABLE_STRING_8)
|
write_string (s: READABLE_STRING_8)
|
||||||
@@ -109,6 +128,9 @@ feature -- Output operation
|
|||||||
|
|
||||||
feature {NONE} -- Implementation: Access
|
feature {NONE} -- Implementation: Access
|
||||||
|
|
||||||
|
crlf: STRING = "%R%N"
|
||||||
|
-- End of header
|
||||||
|
|
||||||
output: WGI_OUTPUT_STREAM
|
output: WGI_OUTPUT_STREAM
|
||||||
-- Server output channel
|
-- Server output channel
|
||||||
|
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ feature -- Handle responses
|
|||||||
h.put_content_length (a_description.count)
|
h.put_content_length (a_description.count)
|
||||||
h.put_current_date
|
h.put_current_date
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.bad_request)
|
res.set_status_code ({HTTP_STATUS_CODE}.bad_request)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (a_description)
|
res.write_string (a_description)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ feature -- Handle responses
|
|||||||
h.put_content_length (a_description.count)
|
h.put_content_length (a_description.count)
|
||||||
h.put_current_date
|
h.put_current_date
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.precondition_failed)
|
res.set_status_code ({HTTP_STATUS_CODE}.precondition_failed)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (a_description)
|
res.write_string (a_description)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ feature -- Handle responses
|
|||||||
h.put_content_length (a_description.count)
|
h.put_content_length (a_description.count)
|
||||||
h.put_current_date
|
h.put_current_date
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.internal_server_error)
|
res.set_status_code ({HTTP_STATUS_CODE}.internal_server_error)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (a_description)
|
res.write_string (a_description)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -220,7 +220,7 @@ feature -- Handle responses
|
|||||||
h.put_content_length (a_description.count)
|
h.put_content_length (a_description.count)
|
||||||
h.put_current_date
|
h.put_current_date
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.not_implemented)
|
res.set_status_code ({HTTP_STATUS_CODE}.not_implemented)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (a_description)
|
res.write_string (a_description)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ feature -- Handle responses
|
|||||||
h.put_content_length (a_description.count)
|
h.put_content_length (a_description.count)
|
||||||
h.put_current_date
|
h.put_current_date
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.method_not_allowed)
|
res.set_status_code ({HTTP_STATUS_CODE}.method_not_allowed)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (a_description)
|
res.write_string (a_description)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ feature -- Handle responses
|
|||||||
h.put_content_length (a_description.count)
|
h.put_content_length (a_description.count)
|
||||||
h.put_current_date
|
h.put_current_date
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.not_found)
|
res.set_status_code ({HTTP_STATUS_CODE}.not_found)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (a_description)
|
res.write_string (a_description)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ feature -- Handle responses
|
|||||||
h.put_content_length (a_description.count)
|
h.put_content_length (a_description.count)
|
||||||
h.put_current_date
|
h.put_current_date
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.not_modified)
|
res.set_status_code ({HTTP_STATUS_CODE}.not_modified)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (a_description)
|
res.write_string (a_description)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -279,7 +279,7 @@ feature -- Handle responses
|
|||||||
h.put_content_length (a_description.count)
|
h.put_content_length (a_description.count)
|
||||||
h.put_current_date
|
h.put_current_date
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.conflict)
|
res.set_status_code ({HTTP_STATUS_CODE}.conflict)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (a_description)
|
res.write_string (a_description)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ feature -- Execution
|
|||||||
|
|
||||||
h.put_content_length (s.count)
|
h.put_content_length (s.count)
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (s)
|
res.write_string (s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -136,7 +136,7 @@ feature -- Execution
|
|||||||
h.put_content_type_text_html
|
h.put_content_type_text_html
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||||
h.put_content_length (s.count)
|
h.put_content_length (s.count)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
if not req.request_method.same_string ({HTTP_REQUEST_METHODS}.method_head) then
|
if not req.request_method.same_string ({HTTP_REQUEST_METHODS}.method_head) then
|
||||||
res.write_string (s)
|
res.write_string (s)
|
||||||
end
|
end
|
||||||
@@ -161,13 +161,13 @@ feature -- Execution
|
|||||||
h.put_content_type (ct)
|
h.put_content_type (ct)
|
||||||
h.put_content_length (f.count)
|
h.put_content_length (f.count)
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
else
|
else
|
||||||
create h.make
|
create h.make
|
||||||
h.put_content_type ({HTTP_MIME_TYPES}.application_force_download)
|
h.put_content_type ({HTTP_MIME_TYPES}.application_force_download)
|
||||||
h.put_content_length (f.count)
|
h.put_content_length (f.count)
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
end
|
end
|
||||||
if not req.request_method.same_string ({HTTP_REQUEST_METHODS}.method_head) then
|
if not req.request_method.same_string ({HTTP_REQUEST_METHODS}.method_head) then
|
||||||
res.write_file_content (fn)
|
res.write_file_content (fn)
|
||||||
@@ -186,7 +186,7 @@ feature -- Execution
|
|||||||
s.append ("Resource %"" + uri + "%" not found%N")
|
s.append ("Resource %"" + uri + "%" not found%N")
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.not_found)
|
res.set_status_code ({HTTP_STATUS_CODE}.not_found)
|
||||||
h.put_content_length (s.count)
|
h.put_content_length (s.count)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (s)
|
res.write_string (s)
|
||||||
res.flush
|
res.flush
|
||||||
end
|
end
|
||||||
@@ -202,7 +202,7 @@ feature -- Execution
|
|||||||
s.append ("Resource %"" + uri + "%": Access denied%N")
|
s.append ("Resource %"" + uri + "%": Access denied%N")
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.forbidden)
|
res.set_status_code ({HTTP_STATUS_CODE}.forbidden)
|
||||||
h.put_content_length (s.count)
|
h.put_content_length (s.count)
|
||||||
res.write_headers_string (h.string)
|
res.write_header_text (h.string)
|
||||||
res.write_string (s)
|
res.write_string (s)
|
||||||
res.flush
|
res.flush
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -73,12 +73,12 @@ feature -- Status setting
|
|||||||
|
|
||||||
feature -- Header output operation
|
feature -- Header output operation
|
||||||
|
|
||||||
write_headers_string (a_headers: READABLE_STRING_8)
|
write_header_text (a_headers: READABLE_STRING_8)
|
||||||
require
|
require
|
||||||
status_set: status_is_set
|
status_set: status_is_set
|
||||||
header_not_committed: not header_committed
|
header_not_committed: not header_committed
|
||||||
do
|
do
|
||||||
wgi_response.write_headers (a_headers)
|
wgi_response.write_header_text (a_headers)
|
||||||
ensure
|
ensure
|
||||||
status_set: status_is_set
|
status_set: status_is_set
|
||||||
header_committed: header_committed
|
header_committed: header_committed
|
||||||
@@ -107,7 +107,7 @@ feature -- Header output operation
|
|||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
wgi_response.write_headers (h.string)
|
wgi_response.write_header_text (h.string)
|
||||||
ensure
|
ensure
|
||||||
header_committed: header_committed
|
header_committed: header_committed
|
||||||
status_set: status_is_set
|
status_set: status_is_set
|
||||||
|
|||||||
Reference in New Issue
Block a user