Added connection header related functions.

- WSF_REQUEST.is_keep_alive_http_connection: BOOLEAN
  - HTTP_HEADER_MODIFIER.put_connection_keep_alive
  - HTTP_HEADER_MODIFIER.put_connection_close
In Standalone request handler code, better detection of Connection: keep-alive header.
This commit is contained in:
2016-10-18 13:22:32 +02:00
parent 4a47a00747
commit c34f89df9b
7 changed files with 82 additions and 19 deletions

View File

@@ -544,6 +544,26 @@ feature -- Others
put_pragma ("no-cache")
end
feature -- Connection
put_connection (a_conn: READABLE_STRING_8)
-- Put "Connection" header with `a_conn' value.
do
put_header_key_value ({HTTP_HEADER_NAMES}.header_connection, a_conn)
end
put_connection_keep_alive
-- Put "Connection" header with "keep-alive".
do
put_connection ("keep-alive")
end
put_connection_close
-- Put "Connection" header with "close".
do
put_connection ("close")
end
feature -- Redirection
put_location (a_uri: READABLE_STRING_8)

View File

@@ -455,14 +455,11 @@ feature -- Parsing
-- Except for HTTP/1.0, persistent connection is the default.
is_persistent_connection_requested := True
if is_http_version_1_0 then
is_persistent_connection_requested := attached request_header_map.item ("Connection") as l_connection and then
l_connection.is_case_insensitive_equal_general ("keep-alive")
is_persistent_connection_requested := has_keep_alive_http_connection_header (request_header_map)
else
-- By default HTTP:1/1 support persistent connection.
if attached request_header_map.item ("Connection") as l_connection then
if l_connection.is_case_insensitive_equal_general ("close") then
is_persistent_connection_requested := False
end
if has_close_http_connection_header (request_header_map) then
is_persistent_connection_requested := False
else
is_persistent_connection_requested := True
end
@@ -476,6 +473,46 @@ feature -- Parsing
end
end
has_keep_alive_http_connection_header (h_map: like request_header_map): BOOLEAN
-- Does Current request header map `h_map' have "keep-alive" connection header?
local
i: INTEGER
do
if attached h_map.item ("Connection") as l_connection then
-- Could be for instance "keep-alive, Upgrade"
i := l_connection.substring_index ("keep-alive", 1)
if i > 0 then
i := i + 9 -- "keep-alive" has 10 characters
check i <= l_connection.count end
if i = l_connection.count then
Result := True
else
Result := l_connection [i + 1] = ',' or l_connection [i + 1].is_space
end
end
end
end
has_close_http_connection_header (h_map: like request_header_map): BOOLEAN
-- Does Current request header map `h_map' have "close" connection header?
local
i: INTEGER
do
if attached h_map.item ("Connection") as l_connection then
-- Could be for instance "close, ..."
i := l_connection.substring_index ("close", 1)
if i > 0 then
i := i + 4 -- "close" has 5 characters
check i <= l_connection.count end
if i = l_connection.count then
Result := True
else
Result := l_connection [i + 1] = ',' or l_connection [i + 1].is_space
end
end
end
end
analyze_request_line (line: STRING)
-- Analyze `line' as a HTTP request line.
-- note: may update `has_error'.

View File

@@ -1200,11 +1200,19 @@ feature -- HTTP_*
http_connection: detachable READABLE_STRING_8
-- Contents of the Connection: header from the current wgi_request, if there is one.
-- Example: 'Keep-Alive'.
-- Example: 'keep-alive'.
do
Result := wgi_request.http_connection
end
is_keep_alive_http_connection: BOOLEAN
-- Is a keep-alive connection?
do
if attached http_connection as conn then
Result := conn.starts_with ("keep-alive")
end
end
http_expect: detachable READABLE_STRING_8
-- The Expect request-header field is used to indicate that particular server behaviors are required by the client.
-- Example: '100-continue'.

View File

@@ -291,11 +291,8 @@ feature {NONE} -- Implementation
response.set_status_code (a_status_code)
response.header.put_content_type_text_html
response.header.put_content_length (s.count)
if
attached request.http_connection as l_connection and then
l_connection.is_case_insensitive_equal_general ("keep-alive")
then
response.header.put_header_key_value ("Connection", "keep-alive")
if request.is_keep_alive_http_connection then
response.header.put_connection_keep_alive
end
response.put_string (s)
end