Applications do not have to provide native support for all protocols, they can in many situations rely on the support of proxies and gateways to help doing the job. Proxy servers are often used to carry client requests through a firewall where they can provide services like corporate caching and other network optimizations. Both Proxy servers and gateways can serve as "protocol translators" which can convert a request in the main Web protocol, HTTP, to an equivalent request in another protocol, for example NNTP, FTP, or Gopher. In case a proxy server or a gateway is available to the application, it can therefore by use of HTTP forward all requests to for example a proxy server which then handle the communications with the remote server, for example using FTP about the document and return it to the application (proxy client) using HTTP.
Libwww supports both proxies and gateways through the HTProxy module and all requests can be redirected to a proxy or a gateway, even requests on the local file system. Of course, the Library can also be used in proxy or gateway applications which in terms can use other proxies or gateways so that a single request can be passed through a series of intermediate agents.
There is one main mechanism for registering both proxies and gateways but there are two different APIs to follow. It is free to the application to chose which one suits it the best, the functionality provided by the Library is the same in both cases. The first API is based on a set of registration functions as we have seen it so often through out this guide. Regardless of the registration mechanism used, proxy servers are always rated higher than gateways so if both a proxy server and a gateway is registered for the same access method, the proxy server will be used.
Constructors, Destructors and Methods
For backwards compatibility with most other Web clients, you can set up proxies and gateways using environment variables. This is generally discouraged as environment variables don't work on all platforms and they are only read at appplication startup. Using the HTProxy API allow you to change proxies and gateways dynamically at any time.
On Unix, you can use a sh script like this to set up proxies and then start your application:
#!/bin/sh http_proxy="http://your.proxy.server:8080/"; export http_proxy ftp_proxy="http://your.proxy.server:8080/"; export ftp_proxy gopher_proxy="http://your.proxy.server:8080/"; export gopher_proxy wais_proxy="http://your.proxy.server:8080/"; export wais_proxy no_proxy="cern.ch,ncsa.uiuc.edu,some.host:8080" export no_proxy exec webbot $@
One way to do this under Win32 is to add the following lines to your system environment:
set http_proxy=http://groucho.marx.edu:1028 set no_proxy=harpo.marx.edu zeppo.marx.edu chico.marx.edu