You've already forked lazarus-ccr
LazMapViewer: Fix error 302 in Synapse download engine
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6826 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -23,7 +23,7 @@ unit mvDLESynapse;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
mvDownloadEngine, SysUtils, Classes, httpsend;
|
mvDownloadEngine, SysUtils, Classes, ssl_openssl, httpsend;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -65,6 +65,8 @@ end;
|
|||||||
procedure TMVDESynapse.DownloadFile(const Url: string; str: TStream);
|
procedure TMVDESynapse.DownloadFile(const Url: string; str: TStream);
|
||||||
var
|
var
|
||||||
FHttp: THTTPSend;
|
FHttp: THTTPSend;
|
||||||
|
realURL: String;
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
inherited DownloadFile(Url, str);
|
inherited DownloadFile(Url, str);
|
||||||
FHttp := THTTPSend.Create;
|
FHttp := THTTPSend.Create;
|
||||||
@ -79,9 +81,26 @@ begin
|
|||||||
|
|
||||||
if FHTTP.HTTPMethod('GET', Url) then
|
if FHTTP.HTTPMethod('GET', Url) then
|
||||||
begin
|
begin
|
||||||
str.Seek(0, soFromBeginning);
|
// If its a 301 or 302 we need to do more processing
|
||||||
str.CopyFrom(FHTTP.Document, 0);
|
if (FHTTP.ResultCode = 301) or (FHTTP.ResultCode = 302) then
|
||||||
str.Position := 0;
|
begin
|
||||||
|
// Check the headers for the Location header
|
||||||
|
for i := 0 to FHTTP.Headers.Count -1 do
|
||||||
|
begin
|
||||||
|
// Extract the URL
|
||||||
|
if Copy(FHTTP.Headers[i], 1, 8) = 'Location' then
|
||||||
|
realURL := copy(FHTTP.Headers[i], 11, Length(FHTTP.Headers[i]) - 10); //11);
|
||||||
|
end;
|
||||||
|
// If we have a URL, run it through the same function
|
||||||
|
if Length(realURL) > 1 then
|
||||||
|
DownloadFile(realURL, str);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
str.Seek(0, soFromBeginning);
|
||||||
|
str.CopyFrom(FHTTP.Document, 0);
|
||||||
|
str.Position := 0;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
FHttp.Free;
|
FHttp.Free;
|
||||||
|
Reference in New Issue
Block a user