Forward HTTP Requests

Supported by

 

  TsgcWebSocketHTTPServer

  TsgcWebSocketServer_HTTPAPI

  TsgcWSHTTPWebBrokerBridgeServer

  TsgcWSHTTP2WebBrokerBridgeServer

  TsgcWSServer_HTTPAPI_WebBrokerBridge

 

You can configure the server to forward some HTTP requests to another server, this is very useful when you have more than one server and only one server is listening on a public address.

 

Example: you can configure your server, to forward to another server all requests to /internal while all other requests are handled by sgcWebSockets server.

 

Use the event OnBeforeForwardHTTP to check if the URL requested must be forwarded and if it is, then set the URL to forward.

 

Example: if you want to forward all requests to the document "/internal" to the server "localhost:8080", do the following:

 


void OnBeforeForwardHTTP(TsgcWSConnection Connection, TsgcWSHTTPRequestInfo ARequestInfo, 
  ref TsgcWSServerForwardHTTP aForward)
begin
  if (ARequestInfo.Document == "/internal")
  {
    aForward.Enabled = true;
    aForward.URL = "http://localhost:8080";
  }
}		

Other Options

When you want forward an HTTP request, you have the additional options:

 

1. By default, the request if forwarded using the original document. Example: if you forward the request http://localhost:8080/internal to the internal server http://localhost:5555, the forwarded URL will be http://localhost:5555/internal. But you can modify the Document, using the Document property of Forward object (by default will use the same of the original request).

 

aForward.Document = "/NewInternal"

 

2. If you forward a secure HTTP connection (HTTPs), you can customize the SSL/TLS options, in TLSOptions property of Forward object. Example: set the TLS version

 

aForward.TLSOptions.Version = tls1_2

 

 

3. The following properties can be used to customize the HTTP request: