Skip to content

Commit fda6334

Browse files
Merge pull request #11 from Dzyszla/master
Multidomain origin
2 parents def71fb + 866a310 commit fda6334

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Horse.CORS.pas

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,22 @@ implementation
4343
LExposedHeaders: string;
4444

4545
procedure CORS(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED(FPC)}TNextProc{$ELSE} TProc {$ENDIF});
46+
var
47+
sl: TArray<String>;
48+
Allowed, Origin: String;
4649
begin
47-
Res.RawWebResponse.SetCustomHeader('Access-Control-Allow-Origin', LAllowedOrigin);
50+
Allowed := LAllowedOrigin;
51+
Origin := Req.Headers['Origin'];
52+
53+
if Allowed <> '*' then
54+
begin
55+
sl := Allowed.Split([',', ';', ' '], TStringSplitOptions.ExcludeEmpty);
56+
57+
if not MatchText(Origin, sl) then
58+
Origin := 'null';
59+
end;
60+
61+
Res.RawWebResponse.SetCustomHeader('Access-Control-Allow-Origin', Origin);
4862
Res.RawWebResponse.SetCustomHeader('Access-Control-Allow-Credentials', LAllowedCredentials);
4963
Res.RawWebResponse.SetCustomHeader('Access-Control-Allow-Headers', LAllowedHeaders);
5064
Res.RawWebResponse.SetCustomHeader('Access-Control-Allow-Methods', LAllowedMethods);

0 commit comments

Comments
 (0)