Using a Squid Proxy with IPWorks Components
Squid is a widely used HTTP proxy server, and IPWorks components can connect through it like any other HTTP proxy. Squid handles plain HTTP requests directly, while HTTPS requests are passed through the proxy using HTTP tunneling (the CONNECT method), so that the TLS connection is made end-to-end between the component and the remote server.
HTTP and HTTPS Requests
The HTTP component (and other HTTP-based components, such as REST, SOAP, and WebUpload) supports both HTTP and HTTPS URLs, and connects through a proxy using the Proxy property. Set the Server and Port fields of the Proxy property to the host name and port of the Squid proxy (port 3128 by default).
HTTP http = new HTTP();
http.Proxy.Server = "proxy.example.com";
http.Proxy.Port = 3128;
// HTTPS requests are tunneled through the proxy automatically.
http.Get("https://www.example.com/");
// HTTP requests are sent to the proxy directly.
http.Get("http://www.example.com/");
By default, the SSL field of the Proxy property is set to psAutomatic, which tunnels requests for HTTPS URLs through the proxy and sends requests for HTTP URLs to the proxy directly. To always tunnel requests through the proxy, including requests for HTTP URLs, set the SSL field to psTunnel.
http.Proxy.SSL = ProxySSLTypes.psTunnel;
Proxy Authentication
If the Squid proxy requires authentication, set the User and Password fields of the Proxy property. By default, Basic authentication is used; however, the AuthScheme field can be set to use a different scheme, such as NTLM or Negotiate (Kerberos), if the proxy is configured for it.
http.Proxy.User = "PROXY_USER";
http.Proxy.Password = "PROXY_PASSWORD";
http.Proxy.AuthScheme = ProxyAuthSchemes.authBasic;
Using the System Proxy Settings
On Windows, the component can also use the proxy configured in the system's settings, instead of specifying the proxy explicitly. To do so, set the AutoDetect field of the Proxy property to true.
http.Proxy.AutoDetect = true;
Non-HTTP Components
Components that use protocols other than HTTP (such as FTP, SMTP, IMAP, and TCPClient) can also connect through a Squid proxy by tunneling the connection, as long as the proxy is configured to allow tunneling to the destination port. To do so, set the FirewallType field of the component's Firewall property to fwTunnel, and set the Host and Port fields to the proxy's host name and port.
SMTP smtp = new SMTP();
// Tunnel the connection to the mail server through the Squid proxy.
smtp.Firewall.FirewallType = FirewallTypes.fwTunnel;
smtp.Firewall.Host = "proxy.example.com";
smtp.Firewall.Port = 3128;
smtp.MailServer = "mail.example.com";
Note that by default, Squid only allows tunneling to port 443. To tunnel connections to other ports (for example, 587 for SMTP or 993 for IMAP), the proxy's SSL_ports and CONNECT access rules must be configured to allow them.
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.