- (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:
Jocelyn Fiat
2011-11-25 20:43:04 +01:00
parent e0ec84611e
commit cdfc6851e7
15 changed files with 78 additions and 38 deletions

View File

@@ -20,7 +20,8 @@ feature {NONE} -- Initialization
execute (req: WGI_REQUEST; res: WGI_RESPONSE)
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")
end

View File

@@ -68,7 +68,22 @@ feature -- Status setting
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
status_set: status_is_set
header_not_committed: not header_committed

View File

@@ -75,12 +75,31 @@ feature -- Status setting
feature -- Header output operation
write_headers (a_headers: READABLE_STRING_8)
write_header_text (a_text: READABLE_STRING_8)
do
write (a_headers)
write (a_text)
write (crlf)
header_committed := True
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
write_string (s: READABLE_STRING_8)
@@ -109,6 +128,9 @@ feature -- Output operation
feature {NONE} -- Implementation: Access
crlf: STRING = "%R%N"
-- End of header
output: WGI_OUTPUT_STREAM
-- Server output channel