Reputation: 23
I'm thinking of writing a Proxy Server. When I specify and activate the port using the TIdHTTPProxyServer
component, the proxy server works properly. It's okay so far, but I can't password it and I can't open an IPv6 proxy. It's just an IPv4 proxy. I couldn't find much documentation on this.
Upvotes: 0
Views: 287
Reputation: 596497
I can't password it
TIdHTTPProxyServer
does not currently implement any authentication of its own.
HTTP authentication between the client and target server is handled transparently between the two of them, TIdHTTPProxyServer
is not involved in that process.
If you want to password-protect the proxy itself, you will have to manually handle authentication in the proxy's OnHTTPBeforeCommand
event. Check the client's request headers (in the event's AContext.Headers
property) for a Proxy-Authorization
header, and if it is not present, or its credentials fail, then manually send the client (via the AContext.Connection
property) an HTTP 407
response containing an appropriate Proxy-Authenticate
header, and then raise
an exception (or disconnect the AContext.Connection
) to stop processing the current proxy request.
I can't open an IPv6 proxy. It's just an IPv4 proxy.
TIdHTTPProxyServer
can handle both IPv4 and IPv6, but it will require some manual setup.
Whichever IP version Indy is compiled for by default is specified in the global ID_DEFAULT_IP_VERSION
constant in Indy's IdGlobal
unit (it is set to IPv4, unless Indy is compiled with IdIPv6
defined in IdCompilerDefines.inc
).
Listening IP/port pairs can be configured in the proxy's Bindings
collection. You can specify an IPVersion
for each binding. The IPVersion
is set to ID_DEFAULT_IP_VERSION
by default.
If you don't specify any Bindings
entries, the proxy's DefaultPort
property is used instead. The proxy will then open either 1 or 2 listening ports, depending on platform and OS capabilities. If 1 port is opened, it will use ID_DEFAULT_IP_VERSION
. If 2 ports are opened, 1 will be IPv4 and 1 will be IPv6.
So, if you want control over the setup of the listening IP/ports, don't leave the Bindings
empty.
Once a client has connected to a listening port, the TIdHTTPProxyServerContext.OutboundClient
object that is used to connect to the next HTTP server will use ID_DEFAULT_IP_VERSION
by default. You can override this in the proxy's OnHTTPBeforeCommand
event, by casting the event's AContext.OutboundClient
property to TIdTCPClient
and then setting its IPVersion
property.
Upvotes: 1