|
@@ -5,7 +5,7 @@ unit pkglnet;
|
|
|
interface
|
|
|
|
|
|
uses
|
|
|
- SysUtils, Classes, StrUtils,
|
|
|
+ SysUtils, Classes,
|
|
|
lnet, lftp, lhttp, pkgdownload;
|
|
|
|
|
|
Type
|
|
@@ -35,7 +35,7 @@ Type
|
|
|
implementation
|
|
|
|
|
|
uses
|
|
|
- pkgmessages;
|
|
|
+ pkgmessages, uriparser;
|
|
|
|
|
|
{ TLNetDownloader }
|
|
|
|
|
@@ -69,47 +69,20 @@ end;
|
|
|
|
|
|
procedure TLNetDownloader.HTTPDownload(const URL: String; Dest: TStream);
|
|
|
var
|
|
|
- aURL, Host, URI, FileName, AltFileName: string;
|
|
|
- index, Port: integer;
|
|
|
+ URI: TURI;
|
|
|
begin
|
|
|
FOutStream:=Dest;
|
|
|
{ parse aURL }
|
|
|
- aURL := URL;
|
|
|
- if not (Copy(aURL, 1, 7) = 'http://') then begin
|
|
|
- Error('URL should start with http://.');
|
|
|
- Exit;
|
|
|
- end;
|
|
|
-
|
|
|
- index := PosEx('/', aURL, 8);
|
|
|
- if index = 0 then begin
|
|
|
- aURL := aURL + '/index.html';
|
|
|
- index := PosEx('/', aURL, 8);
|
|
|
- end;
|
|
|
+ URI := ParseURI(URL);
|
|
|
+
|
|
|
+ if URI.Port = 0 then
|
|
|
+ URI.Port := 80;
|
|
|
|
|
|
- Host := Copy(aURL, 8, index-8);
|
|
|
- URI := Copy(aURL, index, Length(aURL) + 1 - index);
|
|
|
- index := Pos(':', Host);
|
|
|
- if index > 0 then
|
|
|
- begin
|
|
|
- Port := StrToIntDef(Copy(Host, index+1, Length(Host)-index), -1);
|
|
|
- if (Port < 0) or (Port > 65535) then begin
|
|
|
- Error('Port number out of range.');
|
|
|
- Exit;
|
|
|
- end;
|
|
|
- SetLength(Host, index-1);
|
|
|
- end else
|
|
|
- Port := 80;
|
|
|
-
|
|
|
- index := RPos('/', URI);
|
|
|
- if index > 0 then
|
|
|
- FileName := Copy(URI, index+1, Length(URI)-index);
|
|
|
- if Length(FileName) = 0 then
|
|
|
- FileName := 'index.html';
|
|
|
-
|
|
|
- FHTTP.Host := Host;
|
|
|
+ FHTTP.Host := URI.Host;
|
|
|
FHTTP.Method := hmGet;
|
|
|
- FHTTP.Port := Port;
|
|
|
- FHTTP.URI := URI;
|
|
|
+ FHTTP.Port := URI.Port;
|
|
|
+ FHTTP.URI := '/' + URI.Document;
|
|
|
+ Writeln(FHTTP.Host + FHTTP.URI);
|
|
|
FHTTP.SendRequest;
|
|
|
|
|
|
FQuit:=False;
|