While trying to use THttpCli from the ICS suite I bumped into some issues related to the "Host:" header and target port different from 80.
This is a short description, for whoever might be interested.


The client is written in Delphi 3, using the beta version of ICS as of June 17, 2003.
The server is a Tomcat 4.1.24, embedded in a JBoss 3.2.1., working on port 8080
Both client and server are on the same machine (not relevant, but that's the fact anyway)
For the proxy part I used a 2.3-STABLE4 Squid.
The proxy is on a different machine.

Issue 1

I GET-request a page from the server. The server responds with a 302-redirect. I mention that the page is dynamically-generated and is protected by J2EE servlet form-authentication mechanisms. This is not relevant for the issue on hand, but I mention it anyway, being the cause of the redirect.
Because THttpCli encodes only the host machine in the "Host:" header, the logic inside the server creates the "Location:" header of the response using only the host machine and not the port. I believe this is the correct behavior since the server has no way of knowing how I reached it (e.g. might have been through a port relay).
The final outcome is that THttpCli tries to follow the redirect but obviously fails, because the location it gets uses the default port (80) instead of the correct one (8080).
After looking into HttpProt.pas I saw that the "Host:" header does not contain neither FPort nor FTargetPort. This is the first correction I made.

Issue 2

Now let's go through a proxy.
As the above patch is in place, all is well and we receive the proper "Location:" to redirect to. However, inside THttpCli, for reasons I did not bother to check, the new location is rebuilt and in that process, the port fragment is lost again. Hence, the redirect sequence fails again, even if we patched the "Host:" header, because the proxy uses the absolute URL provided in the GET header.
That required a second set of patches, in the section rebuilding the FLocation variable. This time I did not afford the time to thorough check and judge my modifications, so I merely added the port value as I saw fit. Luckily it worked.

See for yourself

The resulting code works for me, but I would recommend further inspection from someone really knowing the facts. Anyway, the modified file is here.
For reference, the original file before my modifications is here.
Maybe the changes will be considered worthy and will be incorporated (not necessarily in this exact form) into the next version.