diff --git a/examples/proxy/application_execution.e b/examples/proxy/application_execution.e
index 44440c88..ab54495e 100644
--- a/examples/proxy/application_execution.e
+++ b/examples/proxy/application_execution.e
@@ -21,16 +21,16 @@ feature -- Basic operations
execute
do
- -- NOTE: please enter the target reverse proxy machine + port number here
- -- replace "localhost" and 8080
- send_proxy_response ("localhost", 8080, Current)
+ -- NOTE: please enter the target server uri here
+ -- replace "http://localhost:8080/foobar"
+ send_proxy_response ("http://localhost:8080/foobar", Current)
end
- send_proxy_response (a_hostname: READABLE_STRING_8; a_port: INTEGER; a_rewriter: detachable WSF_URI_REWRITER)
+ send_proxy_response (a_remote: READABLE_STRING_8; a_rewriter: detachable WSF_URI_REWRITER)
local
h: WSF_SIMPLE_REVERSE_PROXY_HANDLER
do
- create h.make (a_hostname, a_port)
+ create h.make (a_remote)
h.set_uri_rewriter (a_rewriter)
h.set_uri_rewriter (create {WSF_AGENT_URI_REWRITER}.make (agent proxy_uri))
h.set_timeout (30) -- 30 seconds
diff --git a/examples/proxy/proxy.ecf b/examples/proxy/proxy.ecf
index 31ef951a..9bf59a52 100644
--- a/examples/proxy/proxy.ecf
+++ b/examples/proxy/proxy.ecf
@@ -10,6 +10,7 @@
+
diff --git a/library/server/wsf_proxy/network/no_ssl/wsf_proxy_socket_factory.e b/library/server/wsf_proxy/network/no_ssl/wsf_proxy_socket_factory.e
new file mode 100644
index 00000000..21c2e7ea
--- /dev/null
+++ b/library/server/wsf_proxy/network/no_ssl/wsf_proxy_socket_factory.e
@@ -0,0 +1,20 @@
+note
+ description: "Summary description for {WSF_PROXY_SOCKET_FACTORY}."
+ author: ""
+ date: "$Date$"
+ revision: "$Revision$"
+
+class
+ WSF_PROXY_SOCKET_FACTORY
+
+inherit
+ WSF_PROXY_SOCKET_FACTORY_I
+
+feature {NONE} -- Implementation
+
+ ssl_socket (a_host: READABLE_STRING_8; a_port: INTEGER): detachable NETWORK_STREAM_SOCKET
+ do
+ check supported: False end
+ end
+
+end
diff --git a/library/server/wsf_proxy/network/ssl/wsf_proxy_socket_factory.e b/library/server/wsf_proxy/network/ssl/wsf_proxy_socket_factory.e
new file mode 100644
index 00000000..ad264908
--- /dev/null
+++ b/library/server/wsf_proxy/network/ssl/wsf_proxy_socket_factory.e
@@ -0,0 +1,30 @@
+note
+ description: "Summary description for {WSF_PROXY_SOCKET_FACTORY}."
+ author: ""
+ date: "$Date$"
+ revision: "$Revision$"
+
+class
+ WSF_PROXY_SOCKET_FACTORY
+
+inherit
+ WSF_PROXY_SOCKET_FACTORY_I
+ redefine
+ is_ssl_supported
+ end
+
+feature {NONE} -- Implementation
+
+ ssl_socket (a_host: READABLE_STRING_8; a_port: INTEGER): detachable SSL_NETWORK_STREAM_SOCKET
+ do
+ if attached create_from_name (a_host) as l_peer_address then
+ create Result.make_client_by_address_and_port (l_peer_address, a_port)
+ end
+ end
+
+feature -- Status
+
+ is_ssl_supported: BOOLEAN = True
+ -- Is https:// supported?
+
+end
diff --git a/library/server/wsf_proxy/network/wsf_proxy_socket_factory_i.e b/library/server/wsf_proxy/network/wsf_proxy_socket_factory_i.e
new file mode 100644
index 00000000..900db008
--- /dev/null
+++ b/library/server/wsf_proxy/network/wsf_proxy_socket_factory_i.e
@@ -0,0 +1,67 @@
+note
+ description: "Summary description for {WSF_PROXY_SOCKET_FACTORY_I}."
+ date: "$Date$"
+ revision: "$Revision$"
+
+deferred class
+ WSF_PROXY_SOCKET_FACTORY_I
+
+inherit
+ INET_ADDRESS_FACTORY
+
+feature -- Access
+
+ socket_from_uri (a_uri: URI): like socket
+ local
+ l_port: INTEGER
+ do
+ if a_uri.is_valid and then attached a_uri.host as l_host then
+ l_port := a_uri.port
+ if a_uri.scheme.is_case_insensitive_equal_general ("https") then
+ if is_ssl_supported then
+ if l_port <= 0 then
+ l_port := 443
+ end
+ Result := ssl_socket (l_host, l_port)
+ end
+ elseif a_uri.scheme.is_case_insensitive_equal_general ("http") then
+ if l_port <= 0 then
+ l_port := 80
+ end
+ Result := socket (l_host, l_port)
+ end
+ end
+ end
+
+feature -- Status
+
+ is_uri_supported (a_uri: URI): BOOLEAN
+ do
+ Result := a_uri.scheme.is_case_insensitive_equal_general ("http")
+ or else (
+ a_uri.scheme.is_case_insensitive_equal_general ("https")
+ and is_ssl_supported
+ )
+ end
+
+ is_ssl_supported: BOOLEAN
+ -- Is https:// supported?
+ do
+ end
+
+feature {NONE} -- Implementation
+
+ socket (a_host: READABLE_STRING_8; a_port: INTEGER): detachable NETWORK_STREAM_SOCKET
+ do
+ if attached create_from_name (a_host) as l_peer_address then
+ create Result.make_client_by_address_and_port (l_peer_address, a_port)
+ end
+ end
+
+ ssl_socket (a_host: READABLE_STRING_8; a_port: INTEGER): detachable NETWORK_STREAM_SOCKET
+ require
+ is_ssl_supported: is_ssl_supported
+ deferred
+ end
+
+end
diff --git a/library/server/wsf_proxy/reverse_proxy/wsf_simple_reverse_proxy_handler.e b/library/server/wsf_proxy/reverse_proxy/wsf_simple_reverse_proxy_handler.e
index ac6753c3..a0ab3c6b 100644
--- a/library/server/wsf_proxy/reverse_proxy/wsf_simple_reverse_proxy_handler.e
+++ b/library/server/wsf_proxy/reverse_proxy/wsf_simple_reverse_proxy_handler.e
@@ -11,10 +11,9 @@ create
feature {NONE} -- Initialization
- make (a_host: READABLE_STRING_8; a_port: INTEGER_32)
+ make (a_remote_uri: READABLE_STRING_8)
do
- create host.make_from_string (a_host)
- port := a_port
+ create remote_uri.make_from_string (a_remote_uri)
timeout := 30 -- seconds. See {NETWORK_SOCKET}.default_timeout
connect_timeout := 5_000 -- 5 seconds.
is_via_header_supported := True
@@ -22,11 +21,8 @@ feature {NONE} -- Initialization
feature -- Access
- host: IMMUTABLE_STRING_8
- -- Hostname of the targetted service.
-
- port: INTEGER
- -- Port number of the targetted service.
+ remote_uri: URI
+ -- Url for the targetted service.
uri_rewriter: detachable WSF_URI_REWRITER assign set_uri_rewriter
-- URI rewriter component, to compute the URI on targetted service
@@ -92,8 +88,14 @@ feature -- Execution
l_protocol: STRING
i: INTEGER
l_completed: BOOLEAN
+ l_remote_uri: like remote_uri
+ l_socket_factory: WSF_PROXY_SOCKET_FACTORY
do
- if attached (create {WSF_PROXY_SOCKET_FACTORY}).socket (host, port) as l_socket then
+ l_remote_uri := remote_uri
+ create l_socket_factory
+ if not l_socket_factory.is_uri_supported (l_remote_uri) then
+ send_error (request, response, {HTTP_STATUS_CODE}.bad_gateway, l_remote_uri.scheme + " is not supported! [for remote " + l_remote_uri.string + "]")
+ elseif attached l_socket_factory.socket_from_uri (l_remote_uri) as l_socket then
l_socket.set_connect_timeout (connect_timeout) -- milliseconds
l_socket.set_timeout (timeout) -- seconds
@@ -101,6 +103,7 @@ feature -- Execution
if l_socket.is_connected then
create l_http_query.make_from_string (request.request_method)
l_http_query.append_character (' ')
+ l_http_query.append (l_remote_uri.path)
l_http_query.append (proxy_uri (request))
l_http_query.append_character (' ')
l_http_query.append (request.server_protocol)
@@ -112,6 +115,13 @@ feature -- Execution
else
create h.make_from_raw_header_data (l_raw_header)
end
+ if attached l_remote_uri.host as l_remote_host then
+ if l_remote_uri.port > 0 then
+ h.put_header_key_value ("Host", l_remote_host + ":" + l_remote_uri.port.out)
+ else
+ h.put_header_key_value ("Host", l_remote_host)
+ end
+ end
-- Via header
if is_via_header_supported then
@@ -138,7 +148,7 @@ feature -- Execution
end
if l_max_forward < 0 then
-- i.e previous Max-Forwards was '0'
- send_error (request, response, {HTTP_STATUS_CODE}.bad_gateway, "Reached maximum number of Forwards, not forwarded to " + host + ":" + port.out)
+ send_error (request, response, {HTTP_STATUS_CODE}.bad_gateway, "Reached maximum number of Forwards, not forwarded to " + l_remote_uri.string)
else
l_socket.put_string (l_http_query)
l_socket.put_string ("%R%N")
@@ -202,10 +212,10 @@ feature -- Execution
send_error (request, response, {HTTP_STATUS_CODE}.internal_server_error, "Can not access request header!")
end
else
- send_error (request, response, {HTTP_STATUS_CODE}.gateway_timeout, "Can not connect " + host + ":" + port.out)
+ send_error (request, response, {HTTP_STATUS_CODE}.gateway_timeout, "Unable to connect " + l_remote_uri.string)
end
else
- send_error (request, response, {HTTP_STATUS_CODE}.bad_gateway, "Host not found!")
+ send_error (request, response, {HTTP_STATUS_CODE}.bad_gateway, "Unable to connect " + l_remote_uri.string)
end
end
diff --git a/library/server/wsf_proxy/wsf_proxy-safe.ecf b/library/server/wsf_proxy/wsf_proxy-safe.ecf
index f07f10df..9dd777ce 100644
--- a/library/server/wsf_proxy/wsf_proxy-safe.ecf
+++ b/library/server/wsf_proxy/wsf_proxy-safe.ecf
@@ -5,23 +5,24 @@
-
+
+
- ssl
no_ssl
+ ssl
-
+
-
+