Better handling of KeepAlives.
git-svn-id: https://svn.code.sf.net/p/synalist/code/trunk@89 7c85be65-684b-0410-a082-b2ed4fbef004
This commit is contained in:
41
httpsend.pas
41
httpsend.pas
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Ararat Synapse | 003.011.004 |
|
| Project : Ararat Synapse | 003.012.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: HTTP client |
|
| Content: HTTP client |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -80,6 +80,7 @@ type
|
|||||||
FMimeType: string;
|
FMimeType: string;
|
||||||
FProtocol: string;
|
FProtocol: string;
|
||||||
FKeepAlive: Boolean;
|
FKeepAlive: Boolean;
|
||||||
|
FKeepAliveTimeout: integer;
|
||||||
FStatus100: Boolean;
|
FStatus100: Boolean;
|
||||||
FProxyHost: string;
|
FProxyHost: string;
|
||||||
FProxyPort: string;
|
FProxyPort: string;
|
||||||
@ -163,6 +164,9 @@ type
|
|||||||
{:If @true (default value), keepalives in HTTP protocol 1.1 is enabled.}
|
{:If @true (default value), keepalives in HTTP protocol 1.1 is enabled.}
|
||||||
property KeepAlive: Boolean read FKeepAlive Write FKeepAlive;
|
property KeepAlive: Boolean read FKeepAlive Write FKeepAlive;
|
||||||
|
|
||||||
|
{:Define timeout for keepalives in seconds!}
|
||||||
|
property KeepAliveTimeout: integer read FKeepAliveTimeout Write FKeepAliveTimeout;
|
||||||
|
|
||||||
{:if @true, then server is requested for 100status capability when uploading
|
{:if @true, then server is requested for 100status capability when uploading
|
||||||
data. Default is @false (off).}
|
data. Default is @false (off).}
|
||||||
property Status100: Boolean read FStatus100 Write FStatus100;
|
property Status100: Boolean read FStatus100 Write FStatus100;
|
||||||
@ -278,6 +282,7 @@ begin
|
|||||||
FDownloadSize := 0;
|
FDownloadSize := 0;
|
||||||
FUploadSize := 0;
|
FUploadSize := 0;
|
||||||
FAddPortNumberToHost := true;
|
FAddPortNumberToHost := true;
|
||||||
|
FKeepAliveTimeout := 300;
|
||||||
Clear;
|
Clear;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -367,6 +372,8 @@ var
|
|||||||
s, su: string;
|
s, su: string;
|
||||||
HttpTunnel: Boolean;
|
HttpTunnel: Boolean;
|
||||||
n: integer;
|
n: integer;
|
||||||
|
pp: string;
|
||||||
|
UsingProxy: boolean;
|
||||||
begin
|
begin
|
||||||
{initial values}
|
{initial values}
|
||||||
Result := False;
|
Result := False;
|
||||||
@ -397,7 +404,7 @@ begin
|
|||||||
FSock.HTTPTunnelUser := '';
|
FSock.HTTPTunnelUser := '';
|
||||||
FSock.HTTPTunnelPass := '';
|
FSock.HTTPTunnelPass := '';
|
||||||
end;
|
end;
|
||||||
|
UsingProxy := (FProxyHost <> '') and not(HttpTunnel);
|
||||||
Sending := FDocument.Size > 0;
|
Sending := FDocument.Size > 0;
|
||||||
{Headers for Sending data}
|
{Headers for Sending data}
|
||||||
status100 := FStatus100 and Sending and (FProtocol = '1.1');
|
status100 := FStatus100 and Sending and (FProtocol = '1.1');
|
||||||
@ -431,12 +438,20 @@ begin
|
|||||||
if s <> '' then
|
if s <> '' then
|
||||||
FHeaders.Insert(0, 'Cookie: ' + s);
|
FHeaders.Insert(0, 'Cookie: ' + s);
|
||||||
{ setting KeepAlives }
|
{ setting KeepAlives }
|
||||||
if not FKeepAlive then
|
pp := '';
|
||||||
FHeaders.Insert(0, 'Connection: close');
|
if UsingProxy then
|
||||||
|
pp := 'Proxy-';
|
||||||
|
if FKeepAlive then
|
||||||
|
begin
|
||||||
|
FHeaders.Insert(0, pp + 'Connection: keep-alive');
|
||||||
|
FHeaders.Insert(0, 'Keep-Alive: ' + IntToStr(FKeepAliveTimeout));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
FHeaders.Insert(0, pp + 'Connection: close');
|
||||||
{ set target servers/proxy, authorizations, etc... }
|
{ set target servers/proxy, authorizations, etc... }
|
||||||
if User <> '' then
|
if User <> '' then
|
||||||
FHeaders.Insert(0, 'Authorization: Basic ' + EncodeBase64(User + ':' + Pass));
|
FHeaders.Insert(0, 'Authorization: Basic ' + EncodeBase64(User + ':' + Pass));
|
||||||
if (FProxyHost <> '') and (FProxyUser <> '') and not(HttpTunnel) then
|
if UsingProxy and (FProxyUser <> '') then
|
||||||
FHeaders.Insert(0, 'Proxy-Authorization: Basic ' +
|
FHeaders.Insert(0, 'Proxy-Authorization: Basic ' +
|
||||||
EncodeBase64(FProxyUser + ':' + FProxyPass));
|
EncodeBase64(FProxyUser + ':' + FProxyPass));
|
||||||
if isIP6(Host) then
|
if isIP6(Host) then
|
||||||
@ -447,7 +462,7 @@ begin
|
|||||||
FHeaders.Insert(0, 'Host: ' + s + ':' + Port)
|
FHeaders.Insert(0, 'Host: ' + s + ':' + Port)
|
||||||
else
|
else
|
||||||
FHeaders.Insert(0, 'Host: ' + s);
|
FHeaders.Insert(0, 'Host: ' + s);
|
||||||
if (FProxyHost <> '') and not(HttpTunnel)then
|
if UsingProxy then
|
||||||
URI := Prot + '://' + s + ':' + Port + URI;
|
URI := Prot + '://' + s + ':' + Port + URI;
|
||||||
if URI = '/*' then
|
if URI = '/*' then
|
||||||
URI := '*';
|
URI := '*';
|
||||||
@ -455,7 +470,7 @@ begin
|
|||||||
FHeaders.Insert(0, UpperCase(Method) + ' ' + URI)
|
FHeaders.Insert(0, UpperCase(Method) + ' ' + URI)
|
||||||
else
|
else
|
||||||
FHeaders.Insert(0, UpperCase(Method) + ' ' + URI + ' HTTP/' + FProtocol);
|
FHeaders.Insert(0, UpperCase(Method) + ' ' + URI + ' HTTP/' + FProtocol);
|
||||||
if (FProxyHost <> '') and not(HttpTunnel) then
|
if UsingProxy then
|
||||||
begin
|
begin
|
||||||
FTargetHost := FProxyHost;
|
FTargetHost := FProxyHost;
|
||||||
FTargetPort := FProxyPort;
|
FTargetPort := FProxyPort;
|
||||||
@ -584,8 +599,18 @@ begin
|
|||||||
if Pos('CHUNKED', s) > 0 then
|
if Pos('CHUNKED', s) > 0 then
|
||||||
FTransferEncoding := TE_CHUNKED;
|
FTransferEncoding := TE_CHUNKED;
|
||||||
end;
|
end;
|
||||||
if Pos('CONNECTION: CLOSE', su) = 1 then
|
if UsingProxy then
|
||||||
|
begin
|
||||||
|
if Pos('PROXY-CONNECTION:', su) = 1 then
|
||||||
|
if Pos('CLOSE', s) > 0 then
|
||||||
ToClose := True;
|
ToClose := True;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
if Pos('CONNECTION:', su) = 1 then
|
||||||
|
if Pos('CLOSE', s) > 0 then
|
||||||
|
ToClose := True;
|
||||||
|
end;
|
||||||
until FSock.LastError <> 0;
|
until FSock.LastError <> 0;
|
||||||
Result := FSock.LastError = 0;
|
Result := FSock.LastError = 0;
|
||||||
if not Result then
|
if not Result then
|
||||||
|
Reference in New Issue
Block a user