Replaced host+port by uri (http://remotemachine:port/path).
Added support for SSL (https).
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="console_application" value="true"/>
|
||||
<variable name="ssl_supported" value="false"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="http" location="..\..\library\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="wsf" location="..\..\library\server\wsf\wsf-safe.ecf"/>
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -5,23 +5,24 @@
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="http" location="..\..\..\library\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
|
||||
<library name="net_ssl" location="$ISE_LIBRARY/unstable/library/network/socket/netssl/net_ssl-safe.ecf">
|
||||
<library name="net_ssl" location="$ISE_LIBRARY\unstable\library\network\socket\netssl\net_ssl-safe.ecf">
|
||||
<condition>
|
||||
<custom name="ssl_supported" value="true"/>
|
||||
</condition>
|
||||
</library>
|
||||
<library name="uri" location="$ISE_LIBRARY\library\text\uri\uri-safe.ecf"/>
|
||||
<library name="wsf" location="..\wsf\wsf-safe.ecf"/>
|
||||
<cluster name="network" location=".\network\" recursive="true">
|
||||
<file_rule>
|
||||
<exclude>ssl</exclude>
|
||||
<exclude>no_ssl</exclude>
|
||||
<exclude>ssl</exclude>
|
||||
</file_rule>
|
||||
<cluster name="network_ssl" location="$\ssl">
|
||||
<cluster name="network_ssl" location="$|ssl\">
|
||||
<condition>
|
||||
<custom name="ssl_supported" value="true"/>
|
||||
</condition>
|
||||
</cluster>
|
||||
<cluster name="network_no_ssl" location="$\no_ssl">
|
||||
<cluster name="network_no_ssl" location="$|no_ssl\">
|
||||
<condition>
|
||||
<custom name="ssl_supported" excluded_value="true"/>
|
||||
</condition>
|
||||
|
||||
Reference in New Issue
Block a user