This function block is used to connect to a remote server via an HTTP proxy server. The function block sends an HTTP CONNECT request to the proxy server, requesting the proxy to establish a tunnel to the remote server.
The function block extends the FB_ProxyHandlerBase. The ConnectToRemoteServer method is overwritten and implements the processing of the HTTP CONNECT request.
The sequence for establishing the connection is as follows:
Call the method ConnectToProxy to establish a connection to the specified proxy server.
Call the method ConnectToRemoteServer. The following steps are processed:
The HTTP request CONNECT is created to establish a connection to the remote server, which is specified by its qualified hostname (iq_sHostname) and the TCP port (i_uiServerPort).
If a callback is registered, the callback method MessageToSend from the registered interface is executed.
The HTTP request is sent to the proxy server.
The response on the HTTP request is received from the proxy server.
The HTTP status code is verified, a value between 200 and 299 is considered as success, for example: HTTP/1.1 200 Connection Established.
If a callback is registered, the callback method VerifyResponse from the registered interface is executed.
If the option i_xUpgradeToTls is set, the method UpgradeToTls of the referenced instance of the FB_TcpClient2 is executed and monitored.
If both methods are completed successfully one after the other, q_xDone = TRUE, the connection to the remote server is established and ready for the data exchange. The instance of the FB_ProxyHandlerHttpConnect is no longer required for this connection.
An implementation example of the function block FB_ProxyHandlerHttpConnect is provided in the application example MQTT Handling. For more information, refer to the MQTT Handling Example Guide.