E2555 Cannot capture symbol 'Aconfig'
leandrobtu opened this issue · 4 comments
leandrobtu commented
Criei um novo projeto, fiz o include via Boss, segui o exemplo porem recebo o erro:
E2555 Cannot capture symbol 'Aconfig'
Estou usando o Delphi Berlin 10.1 Update 2
Podem ajudar ?
Print: https://drive.google.com/file/d/12xddgS8hpqcyOb914GQV48f2s67Pc2pn/view?usp=sharing
dliocode commented
Olá tudo bem?
faz o seguinte teste e veja se funciona corretamente:
class function THorseRateLimit.New(const AConfig: TRateLimitConfig): THorseCallback;
type
TRateLimitOptions = record
Limit: Integer;
Timeout: Integer;
Message: string;
Headers: Boolean;
Current: Integer;
Remaining: Integer;
ResetTime: TDateTime;
SkipFailedRequest: Boolean;
SkipSuccessRequest: Boolean;
end;
var
LStoreConfig: TStoreConfig<TRateLimitConfig>;
LConfigStore: TRateLimitConfig;
LConfig: TRateLimitConfig;
begin
LConfig := AConfig;
CriticalSection.Enter;
try
LStoreConfig := TStoreConfig<TRateLimitConfig>.New(LConfig.Id, LConfig);
finally
CriticalSection.Leave;
end;
if not(Assigned(LStoreConfig.Config.Store)) then
begin
LConfigStore := LStoreConfig.Config;
LConfigStore.Store := TMemoryStore.New();
LStoreConfig.Config := LConfigStore;
end;
LStoreConfig.Config.Store.SetTimeout(LStoreConfig.Config.Timeout);
LStoreConfig.Save(LStoreConfig.Config.Id);
Result :=
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
var
LManagerConfig: TStoreConfig<TRateLimitConfig>;
LWebResponse: TWebResponse;
LStoreCallback: TStoreCallback;
LKey: string;
LMessage: string;
FOptions: TRateLimitOptions;
begin
CriticalSection.Enter;
try
LManagerConfig := TStoreConfig<TRateLimitConfig>.New(LConfig.Id, LConfig);
finally
CriticalSection.Leave;
end;
LKey := 'RL:' + LManagerConfig.Config.Id + ':' + ClientIP(Req);
LStoreCallback := LManagerConfig.Config.Store.Incr(LKey);
FOptions.Limit := LManagerConfig.Config.Limit;
FOptions.Timeout := LManagerConfig.Config.Timeout;
FOptions.Message := LManagerConfig.Config.Message;
FOptions.Headers := LManagerConfig.Config.Headers;
FOptions.Current := LStoreCallback.Current;
FOptions.Remaining := Ifthen(LManagerConfig.Config.Limit < LStoreCallback.Current, 0, LManagerConfig.Config.Limit - LStoreCallback.Current);
FOptions.ResetTime := LStoreCallback.ResetTime;
FOptions.SkipFailedRequest := LManagerConfig.Config.SkipFailedRequest;
FOptions.SkipSuccessRequest := LManagerConfig.Config.SkipSuccessRequest;
if (FOptions.Headers) then
begin
LWebResponse := THorseHackResponse(Res).GetWebResponse;
LWebResponse.SetCustomHeader('X-RateLimit-Limit', FOptions.Limit.ToString);
LWebResponse.SetCustomHeader('X-RateLimit-Remaining', FOptions.Remaining.ToString);
LWebResponse.SetCustomHeader('X-RateLimit-Reset', IntToStr(MillisecondOfTheDay(FOptions.ResetTime)));
end;
if (FOptions.Current > FOptions.Limit) then
begin
THorseHackResponse(Res).GetWebResponse.SetCustomHeader('Retry-After', IntToStr(FOptions.Timeout * 1000));
LMessage := 'Too many requests, please try again later.';
LMessage := Ifthen(FOptions.Message.Trim.IsEmpty, LMessage, FOptions.Message);
Res.Send(LMessage).Status(THTTPStatus.TooManyRequests);
raise EHorseCallbackInterrupted.Create;
end;
try
try
Next;
except
if FOptions.SkipFailedRequest then
LManagerConfig.Config.Store.Decrement(LKey);
raise;
end;
if (FOptions.SkipFailedRequest) and (THorseHackResponse(Req).GetWebResponse.StatusCode >= 400) then
LManagerConfig.Config.Store.Decrement(LKey);
if (FOptions.SkipSuccessRequest) and (THorseHackResponse(Req).GetWebResponse.StatusCode < 400) then
LManagerConfig.Config.Store.Decrement(LKey);
finally
LManagerConfig.Save(LManagerConfig.Config.Id);
end;
end;
end;
dliocode commented
Se funciona me avisa que eu gero uma versão, pelo que eu testei deu certo..
leandrobtu commented
Olá, Sim deu certo!, muito obrigado pelo rápido retorno ! 🙏
dliocode commented
Já subi a nova versão