Skip to content

Commit 84ff17f

Browse files
Merge pull request #17 from CarlosHe/master
enhancement 'skip route' with params
2 parents 2a45065 + a1c3e9c commit 84ff17f

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/Horse.BasicAuthentication.pas

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
unit Horse.BasicAuthentication;
22

33
{$IF DEFINED(FPC)}
4-
{$MODE DELPHI}{$H+}
4+
{$MODE DELPHI}{$H+}
55
{$ENDIF}
66

77
interface
88

99
uses
1010
{$IF DEFINED(FPC)}
11-
SysUtils, StrUtils, base64, Classes,
11+
SysUtils,
12+
base64,
13+
Classes,
1214
{$ELSE}
13-
System.SysUtils, System.NetEncoding, System.Classes, System.StrUtils,
15+
System.SysUtils,
16+
System.NetEncoding,
17+
System.Classes,
1418
{$ENDIF}
15-
Horse, Horse.Commons;
19+
Horse,
20+
Horse.Commons;
1621

1722
const
1823
AUTHORIZATION = 'Authorization';
@@ -85,7 +90,7 @@ procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED
8590
LPathInfo := Req.RawWebRequest.PathInfo;
8691
if LPathInfo = EmptyStr then
8792
LPathInfo := '/';
88-
if MatchText(LPathInfo, Config.SkipRoutes) then
93+
if MatchRoute(LPathInfo, Config.SkipRoutes) then
8994
begin
9095
Next();
9196
Exit;
@@ -96,17 +101,16 @@ procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED
96101
if LBasicAuthenticationEncode.Trim.IsEmpty and not Req.Query.TryGetValue(Config.Header, LBasicAuthenticationEncode) then
97102
begin
98103
Res.Send('Authorization not found').Status(THTTPStatus.Unauthorized).RawWebResponse
99-
{$IF DEFINED(FPC)}
104+
{$IF DEFINED(FPC)}
100105
.WWWAuthenticate := Format('Basic realm=%s', [Config.RealmMessage]);
101-
{$ELSE}
106+
{$ELSE}
102107
.Realm := Config.RealmMessage;
103-
{$ENDIF}
104-
108+
{$ENDIF}
105109
raise EHorseCallbackInterrupted.Create;
106110
end;
107111

108112
if not LBasicAuthenticationEncode.Trim.ToLower.StartsWith(BASIC_AUTH) then
109-
begin
113+
begin
110114
Res.Send('Invalid authorization type').Status(THTTPStatus.Unauthorized);
111115
raise EHorseCallbackInterrupted.Create;
112116
end;

0 commit comments

Comments
 (0)