Skip to content

Commit d45cd03

Browse files
committed
Corrected support of https request in `server_url' (and callers).
Added query `is_https' to indicate if the request is done via a https connection or not.
1 parent 4b49706 commit d45cd03

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

library/server/wsf/src/wsf_request.e

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ note
1616
And also has
1717
execution_variable (a_name: READABLE_STRING_GENERAL): detachable ANY
1818
--| to keep value attached to the request
19+
20+
About https support: `is_https' precises if the request is made through an https connection or not.
21+
1922
]"
2023
date: "$Date$"
2124
revision: "$Revision$"
@@ -120,6 +123,21 @@ feature {NONE} -- Initialization
120123
if meta_variable ({WSF_META_NAMES}.request_time) = Void then
121124
set_meta_string_variable ({WSF_META_NAMES}.request_time, date_time_utilities.unix_time_stamp (Void).out)
122125
end
126+
127+
--| HTTPS support
128+
if attached meta_string_variable ("REQUEST_SCHEME") as l_scheme and then not l_scheme.is_empty then
129+
is_https := l_scheme.is_case_insensitive_equal_general ("https")
130+
elseif attached execution_environment.item ("HTTPS") as l_https and then not l_https.is_empty then
131+
is_https := l_https.is_case_insensitive_equal_general ("on")
132+
or else l_https.is_case_insensitive_equal_general ("yes")
133+
or else l_https.is_case_insensitive_equal_general ("true")
134+
or else l_https.is_case_insensitive_equal_general ("1")
135+
--| Usually, if not empty, this means this is https
136+
--| but it occurs that server (like IIS) sets "off" when this is NOT https
137+
--| so, let's be flexible, and accepts other variants of "on"
138+
else
139+
check is_not_https: is_https = False end
140+
end
123141
end
124142

125143
wgi_request: WGI_REQUEST
@@ -160,6 +178,10 @@ feature -- Destroy
160178

161179
feature -- Status report
162180

181+
is_https: BOOLEAN
182+
-- Is https scheme or protocol?
183+
--| based on REQUEST_SCHEME, or environment variable HTTPS=on
184+
163185
debug_output: STRING_8
164186
do
165187
create Result.make_from_string (request_method + " " + request_uri)
@@ -1738,19 +1760,22 @@ feature -- URL Utility
17381760
do
17391761
s := internal_server_url
17401762
if s = Void then
1741-
if
1742-
server_protocol.count >= 5 and then
1743-
server_protocol.substring (1, 5).is_case_insensitive_equal ("https")
1744-
then
1763+
if is_https then
17451764
create s.make_from_string ("https://")
17461765
else
17471766
create s.make_from_string ("http://")
17481767
end
17491768
s.append (server_name)
17501769
p := server_port
17511770
if p > 0 then
1752-
s.append_character (':')
1753-
s.append_integer (p)
1771+
if is_https and p = 443 then
1772+
-- :443 is default for https, so no need to put it
1773+
elseif not is_https and p = 80 then
1774+
-- :80 is default for http, so no need to put it
1775+
else
1776+
s.append_character (':')
1777+
s.append_integer (p)
1778+
end
17541779
end
17551780
end
17561781
Result := s

0 commit comments

Comments
 (0)