Forward HTTP Requests

From  sgcWebSockets 4.4.6, forward HTTP requests is supported. Reverse proxy is useful when there is a single server listening on a public port and behind it there are other servers that cannot be accessed from a public address. 

Example: you can serve all HTTP requests using our sgcWebSockets server and forward to another server all requests to url "/internal"

Reverse Proxy Configuration 

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

procedure OnBeforeForwardHTTP(Connection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo; aForward: TsgcWSServerForwardHTTP);
  if ARequestInfo.Document = '/internal' then
    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
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Facial Recognition
Telegram Send Message with Buttons

Related Posts