From 59b8fabd5b8b7b5e663e727f233decc44c89757a Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 5 Mar 2019 23:29:16 +0000 Subject: [PATCH] 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 --- .../synapse_downloadengine/mvdlesynapse.pas | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/components/lazmapviewer/source/addons/synapse_downloadengine/mvdlesynapse.pas b/components/lazmapviewer/source/addons/synapse_downloadengine/mvdlesynapse.pas index 36a85c4b0..fa36e9ad9 100644 --- a/components/lazmapviewer/source/addons/synapse_downloadengine/mvdlesynapse.pas +++ b/components/lazmapviewer/source/addons/synapse_downloadengine/mvdlesynapse.pas @@ -23,7 +23,7 @@ unit mvDLESynapse; interface uses - mvDownloadEngine, SysUtils, Classes, httpsend; + mvDownloadEngine, SysUtils, Classes, ssl_openssl, httpsend; type @@ -65,6 +65,8 @@ end; procedure TMVDESynapse.DownloadFile(const Url: string; str: TStream); var FHttp: THTTPSend; + realURL: String; + i: Integer; begin inherited DownloadFile(Url, str); FHttp := THTTPSend.Create; @@ -79,9 +81,26 @@ begin if FHTTP.HTTPMethod('GET', Url) then begin - str.Seek(0, soFromBeginning); - str.CopyFrom(FHTTP.Document, 0); - str.Position := 0; + // If its a 301 or 302 we need to do more processing + if (FHTTP.ResultCode = 301) or (FHTTP.ResultCode = 302) then + 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; finally FHttp.Free;