Patch service rate limiter bug
This commit is contained in:
parent
a6d2075a25
commit
711f13afd1
4 changed files with 23 additions and 5 deletions
|
@ -1,3 +1,6 @@
|
|||
# 2.0.0-alpha.1
|
||||
* Make `ServiceRateLimiter` more fail-proof.
|
||||
|
||||
# 2.0.0-alpha
|
||||
* Angel 2 updates. Remove previous functionality.
|
||||
* Add `CookieSigner`, `RateLimiter`/`InMemoryRateLimiter`/`ServiceRateLimiter`.
|
5
lib/src/helmet.dart
Normal file
5
lib/src/helmet.dart
Normal file
|
@ -0,0 +1,5 @@
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
|
||||
class Helmet {
|
||||
|
||||
}
|
|
@ -21,10 +21,20 @@ class ServiceRateLimiter<Id> extends RateLimiter<Id> {
|
|||
FutureOr<RateLimitingWindow<Id>> getCurrentWindow(
|
||||
RequestContext req, ResponseContext res, DateTime currentTime) async {
|
||||
var id = await getId(req, res);
|
||||
var existing = await service.read(id).catchError((_) => null,
|
||||
test: (e) => e is AngelHttpException && e.statusCode == 404);
|
||||
if (existing != null) {
|
||||
return RateLimitingWindow.fromJson(existing);
|
||||
try {
|
||||
var data = await service.read(id);
|
||||
if (data != null) {
|
||||
return RateLimitingWindow.fromJson(data);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e is AngelHttpException) {
|
||||
if (e.statusCode == 404) {
|
||||
} else {
|
||||
rethrow;
|
||||
}
|
||||
} else {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
var window = RateLimitingWindow(id, currentTime, 0);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel_security
|
||||
version: 2.0.0-alpha
|
||||
version: 2.0.0-alpha.1
|
||||
description: Angel infrastructure for improving security, rate limiting, and more.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/security
|
||||
|
|
Loading…
Reference in a new issue