IndySockets / Indy

Indy - Internet Direct
https://www.indyproject.org
451 stars 153 forks source link

idHttp - IPv6 - IPVersion-ProtocolSwitch on Redirect (HandleRedirects=true) #528

Open tobfel opened 6 months ago

tobfel commented 6 months ago

First reqest is done via IPv6, but when the server response with 301, the RedirectUrl ist not called with the same IP-Protocol-Version. Can be fixed via:

if Request.IPVersion=Id_IPv6 then
       begin
       with TIdURI.Create(LLocation) do
            begin
            URI := LLocation;
            IPVersion := Id_IPv6;
            LLocation := URI;
            Free;
            end;
       end;

in

function TIdHTTPProtocol.ProcessResponse(AIgnoreReplies: array of Int16): TIdHTTPWhatsNext;
...
after:
LLocation := Response.Location;
LMethod := Request.Method;
rlebeau commented 6 months ago

TIdURI is already being used to process the Request.URL inside of TIdCustomHTTP.PrepareRequest(), which is called just after LLocation is assigned to Request.URL. So, rather than modifying LLocation itself, it would probably work/make more sense to instead have PrepareRequest() preserve the existing IPVersion when processing ARequest.URL, eg:

procedure TIdCustomHTTP.PrepareRequest(ARequest: TIdHTTPRequest);
var
  LURI: TIdURI;
  ...
begin
  LURI := TIdURI.Create(ARequest.URL);

  try
    // Add this...?
    LURI.IPVersion := ARequest.IPVersion;
    // or maybe this?
    if ARequest.IPVersion = Id_IPv6 then begin
      LURI.IPVersion := Id_IPv6;
    end;

    ...
  finally
    FreeAndNil(LURI);  // Free URI Object
  end;
end;
rlebeau commented 2 months ago

Was my earlier suggestion helpful to you?