From 5689b89d9099ed1b7c57dc25ae0c4dc81be2cc19 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 17 Sep 2015 15:19:23 +0200 Subject: [PATCH] * Added BasicAuth support --- restemplate.lpr | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/restemplate.lpr b/restemplate.lpr index be4a40e..cdce096 100644 --- a/restemplate.lpr +++ b/restemplate.lpr @@ -151,6 +151,20 @@ begin {$endif} end; +procedure CmdBasicAuth(AData: String); +var + separator: Char; + i: Integer; +begin + separator := AData[1]; + i := 2; + while (i < Length(AData)) and (AData[i] <> separator) do + Inc(i); + + http.UserName := Copy(AData, 2, i - 2); + http.Password := Copy(AData, i + 1, Length(AData)); +end; + function ProcessCommand(ALine: String): Boolean; begin Result := False; @@ -169,6 +183,14 @@ begin Result := True; method := Copy(ALine, 8, Length(ALine)); end else + // We don't include the space here, since we also interpret this following + // char as separator for username and password! (In case the username itself + // contains a space.) + if AnsiStartsStr('BasicAuth', ALine) then + begin + Result := True; + CmdBasicAuth(Copy(ALine, 10, Length(ALine))); + end else if AnsiStartsStr('Call ', ALine) then begin Result := True;