THTTPSend can handle folded headers in HTTP reply
git-svn-id: https://svn.code.sf.net/p/synalist/code/trunk@91 7c85be65-684b-0410-a082-b2ed4fbef004
This commit is contained in:
26
httpsend.pas
26
httpsend.pas
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Ararat Synapse | 003.012.000 |
|
| Project : Ararat Synapse | 003.012.001 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: HTTP client |
|
| Content: HTTP client |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -374,6 +374,8 @@ var
|
|||||||
n: integer;
|
n: integer;
|
||||||
pp: string;
|
pp: string;
|
||||||
UsingProxy: boolean;
|
UsingProxy: boolean;
|
||||||
|
l: TStringList;
|
||||||
|
x: integer;
|
||||||
begin
|
begin
|
||||||
{initial values}
|
{initial values}
|
||||||
Result := False;
|
Result := False;
|
||||||
@ -579,11 +581,20 @@ begin
|
|||||||
{ if need receive headers, receive and parse it }
|
{ if need receive headers, receive and parse it }
|
||||||
ToClose := FProtocol <> '1.1';
|
ToClose := FProtocol <> '1.1';
|
||||||
if FHeaders.Count > 0 then
|
if FHeaders.Count > 0 then
|
||||||
|
begin
|
||||||
|
l := TStringList.Create;
|
||||||
|
try
|
||||||
repeat
|
repeat
|
||||||
s := FSock.RecvString(FTimeout);
|
s := FSock.RecvString(FTimeout);
|
||||||
FHeaders.Add(s);
|
l.Add(s);
|
||||||
if s = '' then
|
if s = '' then
|
||||||
Break;
|
Break;
|
||||||
|
until FSock.LastError <> 0;
|
||||||
|
x := 0;
|
||||||
|
while l.Count > x do
|
||||||
|
begin
|
||||||
|
s := NormalizeHeader(l, x);
|
||||||
|
FHeaders.Add(s);
|
||||||
su := UpperCase(s);
|
su := UpperCase(s);
|
||||||
if Pos('CONTENT-LENGTH:', su) = 1 then
|
if Pos('CONTENT-LENGTH:', su) = 1 then
|
||||||
begin
|
begin
|
||||||
@ -602,16 +613,21 @@ begin
|
|||||||
if UsingProxy then
|
if UsingProxy then
|
||||||
begin
|
begin
|
||||||
if Pos('PROXY-CONNECTION:', su) = 1 then
|
if Pos('PROXY-CONNECTION:', su) = 1 then
|
||||||
if Pos('CLOSE', s) > 0 then
|
if Pos('CLOSE', su) > 0 then
|
||||||
ToClose := True;
|
ToClose := True;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
if Pos('CONNECTION:', su) = 1 then
|
if Pos('CONNECTION:', su) = 1 then
|
||||||
if Pos('CLOSE', s) > 0 then
|
if Pos('CLOSE', su) > 0 then
|
||||||
ToClose := True;
|
ToClose := True;
|
||||||
end;
|
end;
|
||||||
until FSock.LastError <> 0;
|
end;
|
||||||
|
finally
|
||||||
|
l.free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
Result := FSock.LastError = 0;
|
Result := FSock.LastError = 0;
|
||||||
if not Result then
|
if not Result then
|
||||||
Exit;
|
Exit;
|
||||||
|
33
mimepart.pas
33
mimepart.pas
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Ararat Synapse | 002.007.009 |
|
| Project : Ararat Synapse | 002.008.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: MIME support procedures and functions |
|
| Content: MIME support procedures and functions |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -347,42 +347,11 @@ const
|
|||||||
('ZIP', 'application', 'ZIP')
|
('ZIP', 'application', 'ZIP')
|
||||||
);
|
);
|
||||||
|
|
||||||
{:Read header from "Value" stringlist beginning at "Index" position. If header
|
|
||||||
is Splitted into multiple lines, then this procedure de-split it into one line.}
|
|
||||||
function NormalizeHeader(Value: TStrings; var Index: Integer): string;
|
|
||||||
|
|
||||||
{:Generates a unique boundary string.}
|
{:Generates a unique boundary string.}
|
||||||
function GenerateBoundary: string;
|
function GenerateBoundary: string;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
function NormalizeHeader(Value: TStrings; var Index: Integer): string;
|
|
||||||
var
|
|
||||||
s, t: string;
|
|
||||||
n: Integer;
|
|
||||||
begin
|
|
||||||
s := Value[Index];
|
|
||||||
Inc(Index);
|
|
||||||
if s <> '' then
|
|
||||||
while (Value.Count - 1) > Index do
|
|
||||||
begin
|
|
||||||
t := Value[Index];
|
|
||||||
if t = '' then
|
|
||||||
Break;
|
|
||||||
for n := 1 to Length(t) do
|
|
||||||
if t[n] = #9 then
|
|
||||||
t[n] := ' ';
|
|
||||||
if not(t[1] in [' ', '"', ':', '=']) then
|
|
||||||
Break
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
s := s + ' ' + Trim(t);
|
|
||||||
Inc(Index);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
Result := TrimRight(s);
|
|
||||||
end;
|
|
||||||
|
|
||||||
{==============================================================================}
|
{==============================================================================}
|
||||||
|
|
||||||
constructor TMIMEPart.Create;
|
constructor TMIMEPart.Create;
|
||||||
|
39
synautil.pas
39
synautil.pas
@ -1,9 +1,9 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Ararat Synapse | 004.011.003 |
|
| Project : Ararat Synapse | 004.012.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: support procedures and functions |
|
| Content: support procedures and functions |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Copyright (c)1999-2005, Lukas Gebauer |
|
| Copyright (c)1999-2008, Lukas Gebauer |
|
||||||
| All rights reserved. |
|
| All rights reserved. |
|
||||||
| |
|
| |
|
||||||
| Redistribution and use in source and binary forms, with or without |
|
| Redistribution and use in source and binary forms, with or without |
|
||||||
@ -33,7 +33,7 @@
|
|||||||
| DAMAGE. |
|
| DAMAGE. |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
|
| The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
|
||||||
| Portions created by Lukas Gebauer are Copyright (c) 1999-2005. |
|
| Portions created by Lukas Gebauer are Copyright (c) 1999-2008. |
|
||||||
| Portions created by Hernan Sanchez are Copyright (c) 2000. |
|
| Portions created by Hernan Sanchez are Copyright (c) 2000. |
|
||||||
| All Rights Reserved. |
|
| All Rights Reserved. |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -306,6 +306,10 @@ function GetTempFile(const Dir, prefix: AnsiString): AnsiString;
|
|||||||
smaller, string is padded by Pad character.}
|
smaller, string is padded by Pad character.}
|
||||||
function PadString(const Value: AnsiString; len: integer; Pad: AnsiChar): AnsiString;
|
function PadString(const Value: AnsiString; len: integer; Pad: AnsiChar): AnsiString;
|
||||||
|
|
||||||
|
{:Read header from "Value" stringlist beginning at "Index" position. If header
|
||||||
|
is Splitted into multiple lines, then this procedure de-split it into one line.}
|
||||||
|
function NormalizeHeader(Value: TStrings; var Index: Integer): string;
|
||||||
|
|
||||||
var
|
var
|
||||||
{:can be used for your own months strings for @link(getmonthnumber)}
|
{:can be used for your own months strings for @link(getmonthnumber)}
|
||||||
CustomMonthNames: array[1..12] of string;
|
CustomMonthNames: array[1..12] of string;
|
||||||
@ -1757,6 +1761,35 @@ begin
|
|||||||
Result := Value + StringOfChar(Pad, len - length(value));
|
Result := Value + StringOfChar(Pad, len - length(value));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{==============================================================================}
|
||||||
|
|
||||||
|
function NormalizeHeader(Value: TStrings; var Index: Integer): string;
|
||||||
|
var
|
||||||
|
s, t: string;
|
||||||
|
n: Integer;
|
||||||
|
begin
|
||||||
|
s := Value[Index];
|
||||||
|
Inc(Index);
|
||||||
|
if s <> '' then
|
||||||
|
while (Value.Count - 1) > Index do
|
||||||
|
begin
|
||||||
|
t := Value[Index];
|
||||||
|
if t = '' then
|
||||||
|
Break;
|
||||||
|
for n := 1 to Length(t) do
|
||||||
|
if t[n] = #9 then
|
||||||
|
t[n] := ' ';
|
||||||
|
if not(t[1] in [' ', '"', ':', '=']) then
|
||||||
|
Break
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
s := s + ' ' + Trim(t);
|
||||||
|
Inc(Index);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Result := TrimRight(s);
|
||||||
|
end;
|
||||||
|
|
||||||
{==============================================================================}
|
{==============================================================================}
|
||||||
var
|
var
|
||||||
n: integer;
|
n: integer;
|
||||||
|
Reference in New Issue
Block a user