DZ-Jay wrote:
> The
> alternative would be to give the user access to the URL when
> automatic redirections are in place, via a new event.
For this purpose I suggest we trigger the OnHeaderData event at
a slightly different place and make property LastResponse
writeable.
> However,
> Francois had mentioned that the component should do it itself, and in
> that case a smart check is required (as opposed to the simple space
> substitution), but it should be an optional feature enabled by a flag.
How smart, that's the question. If this check was optional it's a good
compromise.
The following beta-function is not very smart, however rather fast. You
are invited to make it smarter (syntax check etc.), it should be copied
to (Overbyte)IcsUrl.pas.
const
{ According to rfc #1738 only the following chars may be used unencoded }
{ within a URL. }
UrlAllowedChars : TCharSet = [
{AlphaNum} 'a'..'z', '0'..'9', 'A'..'Z',
{Specials} '$', '-', '_', '.', '+', '!', '*', '''', '(',
')', ',',
{Reserved} ';', '/', '?', ':', '@', '=', '&'
];
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ Returns zero when encoding is not required otherwise index of the first }
{ character that needs to be encoded. }
function NeedsUrlEncoding(const S: String) : Integer;
var
I : Integer;
begin
I := 1;
while I <= Length(S) do begin
if (S[I] = '%') and (I < Length(S) - 1) and
IsXDigit(S[I + 1]) and IsXDigit(S[I + 2]) then
Inc(I, 2)
else if not (S[I] in UrlAllowedChars) then begin
Result := I;
Exit;
end;
Inc(I);
end;
Result := 0;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function UrlCheckEncode(const S: String): String;
var
I : Integer;
Y : Integer;
X : String[2];
begin
Y := NeedsUrlEncoding(S);
if Y = 0 then begin
Result := S;
Exit;
end;
SetLength(Result, 3 * Length(S));
if Y > 1 then
Move(S[1], Result[1], Y - 1);
I := Y;
while I <= Length(S) do begin
if S[I] in UrlAllowedChars then begin
Result[Y] := S[I];
Inc(Y);
Inc(I);
end
{ Don't encode twice }
else if (S[I] = '%') and (I < Length(S) - 1) and
IsXDigit(S[I + 1]) and IsXDigit(S[I + 2]) then begin
Move(S[I], Result[Y], 3);
Inc(I, 3);
Inc(Y, 3);
end
else begin
X := IntToHex(Ord(S[I]), 2);
Result[Y] := '%';
Result[Y + 1] := X[1];
Result[Y + 2] := X[2];
Inc(Y, 3);
Inc(I);
end;
end;
SetLength(Result, Y - 1);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
--
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
>
> dZ.
>
> --
> DZ-Jay [TeamICS]
> http://www.overbyte.be/eng/overbyte/teamics.html
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be