Added proxy support

This commit is contained in:
Andreas Schneider 2015-10-04 14:31:32 +02:00
parent b1e455022b
commit 76cd385462
2 changed files with 46 additions and 5 deletions

View File

@ -106,6 +106,13 @@ Once the first none-empty line is unrecognized (no command found), the parser wi
`Compress[ed]`
: Adds support for gzip,deflate compression to the connection.
`Proxy <server> <port>`
: Enables HTTP proxy support.
`ProxyAuth <username> <password>`
: Sets authentication for the HTTP proxy.
Same syntax as `BasicAuth`.
`Call <URL>`
: This prepares the actual call by providing the URL to be called.
Variables in the form of `@<variablename>` are replaced accordingly.

View File

@ -69,6 +69,8 @@ type
procedure CmdBasicAuth(AData: String);
procedure CmdHighlight(AData: String);
procedure CmdFormField(AData: String);
procedure CmdProxy(AData: String);
procedure CmdProxyAuth(AData: String);
procedure ProcessCall(AURL: String);
//Helper
procedure WriteHelp;
@ -236,6 +238,16 @@ begin
Result := True;
FHttp.Compressor := TIdCompressorZLib.Create(FHttp);
end else
if AnsiStartsStr('Proxy ', ALine) then
begin
Result := True;
CmdProxy(Copy(ALine, 7, Length(ALine)));
end else
if AnsiStartsStr('ProxyAuth', ALine) then
begin
Result := True;
CmdProxy(Copy(ALine, 10, Length(ALine)));
end else
if AnsiStartsStr('Call ', ALine) then
begin
Result := True;
@ -292,11 +304,7 @@ begin
varName := Trim(Copy(AHeader, 1, i - 1));
varValue := Trim(Copy(AHeader, i + 1, Length(AHeader)));
//Special handling is required for Indy
{if SameText(varName, 'Accept-Encoding') then
FHttp.Request.AcceptEncoding := varValue
else}
FRequest.RawHeaders.AddValue(varName, varValue);
FRequest.RawHeaders.AddValue(varName, varValue);
end;
procedure TRestemplateApplication.CmdBasicAuth(AData: String);
@ -334,6 +342,32 @@ begin
FFormFields.AddFormField(Copy(AData, 1, i - 1), Copy(AData, i + 1, Length(AData)));
end;
procedure TRestemplateApplication.CmdProxy(AData: String);
var
i: Integer;
begin
i := 1;
while (i < Length(AData)) and (AData[i] <> ' ') do
Inc(i);
FHttp.ProxyParams.ProxyServer := Copy(AData, 1, i - 1);
FHttp.ProxyParams.ProxyPort := StrToInt(Copy(AData, i + 1, Length(AData)));
end;
procedure TRestemplateApplication.CmdProxyAuth(AData: String);
var
separator: Char;
i: Integer;
begin
separator := AData[1];
i := 2;
while (i < Length(AData)) and (AData[i] <> separator) do
Inc(i);
FHttp.ProxyParams.ProxyUsername := Copy(AData, 2, i - 2);
FHttp.ProxyParams.ProxyPassword := Copy(AData, i + 1, Length(AData));
end;
procedure TRestemplateApplication.ProcessCall(AURL: String);
var
s: String;