mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 19:49:12 +02:00
* minor http cleanups, use of uriparser
git-svn-id: trunk@5230 -
This commit is contained in:
parent
66c4b79e08
commit
e4cd04aa0e
@ -5,7 +5,7 @@ unit pkglnet;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils, Classes, StrUtils,
|
SysUtils, Classes,
|
||||||
lnet, lftp, lhttp, pkgdownload;
|
lnet, lftp, lhttp, pkgdownload;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
@ -35,7 +35,7 @@ Type
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
pkgmessages;
|
pkgmessages, uriparser;
|
||||||
|
|
||||||
{ TLNetDownloader }
|
{ TLNetDownloader }
|
||||||
|
|
||||||
@ -69,47 +69,20 @@ end;
|
|||||||
|
|
||||||
procedure TLNetDownloader.HTTPDownload(const URL: String; Dest: TStream);
|
procedure TLNetDownloader.HTTPDownload(const URL: String; Dest: TStream);
|
||||||
var
|
var
|
||||||
aURL, Host, URI, FileName, AltFileName: string;
|
URI: TURI;
|
||||||
index, Port: integer;
|
|
||||||
begin
|
begin
|
||||||
FOutStream:=Dest;
|
FOutStream:=Dest;
|
||||||
{ parse aURL }
|
{ parse aURL }
|
||||||
aURL := URL;
|
URI := ParseURI(URL);
|
||||||
if not (Copy(aURL, 1, 7) = 'http://') then begin
|
|
||||||
Error('URL should start with http://.');
|
if URI.Port = 0 then
|
||||||
Exit;
|
URI.Port := 80;
|
||||||
end;
|
|
||||||
|
|
||||||
index := PosEx('/', aURL, 8);
|
FHTTP.Host := URI.Host;
|
||||||
if index = 0 then begin
|
|
||||||
aURL := aURL + '/index.html';
|
|
||||||
index := PosEx('/', aURL, 8);
|
|
||||||
end;
|
|
||||||
|
|
||||||
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.Method := hmGet;
|
FHTTP.Method := hmGet;
|
||||||
FHTTP.Port := Port;
|
FHTTP.Port := URI.Port;
|
||||||
FHTTP.URI := URI;
|
FHTTP.URI := '/' + URI.Document;
|
||||||
|
Writeln(FHTTP.Host + FHTTP.URI);
|
||||||
FHTTP.SendRequest;
|
FHTTP.SendRequest;
|
||||||
|
|
||||||
FQuit:=False;
|
FQuit:=False;
|
||||||
|
Loading…
Reference in New Issue
Block a user