Skip to content

Commit 5dae4ee

Browse files
author
CarlosHe
committed
Compatibility with Lazarus
1 parent bd5a217 commit 5dae4ee

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

src/Horse.BasicAuthentication.pas

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
unit Horse.BasicAuthentication;
2-
2+
{$IF DEFINED(FPC)}
3+
{$MODE DELPHI}{$H+}
4+
{$ENDIF}
35
interface
46

5-
uses Horse, Horse.Commons, System.SysUtils, System.NetEncoding, System.Classes;
7+
uses
8+
{$IF DEFINED(FPC)}
9+
SysUtils, base64, Classes,
10+
{$ELSE}
11+
System.SysUtils, System.NetEncoding, System.Classes,
12+
{$ENDIF}
13+
14+
Horse, Horse.Commons;
615

716
const
817
AUTHORIZATION = 'authorization';
918

1019
type
11-
THorseBasicAuthentication = reference to function(const AUsername, APassword: string): Boolean;
20+
THorseBasicAuthentication = {$IF NOT DEFINED(FPC)} reference to {$ENDIF} function(const AUsername, APassword: string): Boolean;
1221

13-
procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: TProc);
22+
procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED(FPC)} TNextProc {$ELSE} TProc {$ENDIF} );
1423
function HorseBasicAuthentication(const AAuthenticate: THorseBasicAuthentication; const AHeader: string = AUTHORIZATION): THorseCallback;
1524

1625
implementation
@@ -26,11 +35,12 @@ function HorseBasicAuthentication(const AAuthenticate: THorseBasicAuthentication
2635
Result := Middleware;
2736
end;
2837

29-
procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: TProc);
38+
procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED(FPC)} TNextProc {$ELSE} TProc {$ENDIF});
3039
const
3140
BASIC_AUTH = 'basic ';
3241
var
3342
LBasicAuthenticationEncode: string;
43+
LBase64String: string;
3444
LBasicAuthenticationDecode: TStringList;
3545
LIsAuthenticated: Boolean;
3646
begin
@@ -48,7 +58,8 @@ procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: TProc);
4858
LBasicAuthenticationDecode := TStringList.Create;
4959
try
5060
LBasicAuthenticationDecode.Delimiter := ':';
51-
LBasicAuthenticationDecode.DelimitedText := TBase64Encoding.Base64.Decode(LBasicAuthenticationEncode.Replace(BASIC_AUTH, '', [rfIgnoreCase]));
61+
LBase64String := LBasicAuthenticationEncode.Replace(BASIC_AUTH, '', [rfIgnoreCase]);
62+
LBasicAuthenticationDecode.DelimitedText := {$IF DEFINED(FPC)}DecodeStringBase64(LBase64String){$ELSE}TBase64Encoding.Base64.Decode(LBase64String){$ENDIF};
5263
try
5364
LIsAuthenticated := Authenticate(LBasicAuthenticationDecode.Strings[0], LBasicAuthenticationDecode.Strings[1]);
5465
except

0 commit comments

Comments
 (0)