From 6ef2dee997e694fc9d80460d4bbbb39ef6d31ea7 Mon Sep 17 00:00:00 2001 From: Mauran Muthiah Date: Thu, 16 Nov 2017 12:52:39 +0100 Subject: [PATCH 01/10] Updated documentation to describe how to add the middleware --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index 43040f1..49d5918 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,50 @@ Update your `Package.swift` file. let limiter = RateLimiter(rate: Rate(10, per: .minute)) ``` +### Adding middleware +You can add the middleware either globally or to a route group. + +#### Adding Middleware Globally + +#### `Sources/App/Config+Setup.swift` +``` +import RateLimiter +``` + +``` +public func setup() throws { + // ... + + addConfigurable(middleware: RateLimiter(rate: Rate(10, per: .minute)), name: "ratelimiter") +} +``` + +#### `Config/droplet.json` + +Add ratelimiter to the middleware array + +``` +"middleware": [ + "error", + "date", + "file", + "ratelimiter" +], +``` + + +#### Adding Middleware to a Route Group + +```Swift +let limiter = RateLimiter(rate: Rate(10, per: .minute)) + +drop.group(limiter) { group in + // Routes +} +``` + + + ### The `Rate.Interval` enumeration The currently implemented intervals are: From 8ac83b904e1484919d745c579d2e8e9a5bf6a53d Mon Sep 17 00:00:00 2001 From: Mauran Muthiah Date: Thu, 16 Nov 2017 12:54:45 +0100 Subject: [PATCH 02/10] Added markdown syntax highlighting --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 49d5918..9197127 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,11 @@ You can add the middleware either globally or to a route group. #### Adding Middleware Globally #### `Sources/App/Config+Setup.swift` -``` +```swift import RateLimiter ``` -``` +```swift public func setup() throws { // ... @@ -49,13 +49,13 @@ public func setup() throws { Add ratelimiter to the middleware array -``` +```json "middleware": [ "error", "date", "file", "ratelimiter" -], +] ``` From 2f0b3c7607754aece65fc567abeb850954f2cd43 Mon Sep 17 00:00:00 2001 From: Mauran Muthiah Date: Thu, 16 Nov 2017 13:31:45 +0100 Subject: [PATCH 03/10] Added explaination of how the Rate Limiter works --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9197127..4039512 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ Rate Limiter middleware. +**How it works** + +The middleware makes it possible to restrict the number of requests from clients, based on their IP address. ## 📦 Installation From 0c5af5af669dcd3c4cb88eef08ddcf3166b3b6ce Mon Sep 17 00:00:00 2001 From: Mauran Muthiah Date: Thu, 16 Nov 2017 13:32:43 +0100 Subject: [PATCH 04/10] Updated description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4039512..2aecde2 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Rate Limiter middleware. **How it works** -The middleware makes it possible to restrict the number of requests from clients, based on their IP address. +The middleware restricts the number of requests from clients, based on their IP address. ## 📦 Installation From c113a37277b76b9975a6460215247f1fc1b23927 Mon Sep 17 00:00:00 2001 From: Mauran Muthiah Date: Thu, 16 Nov 2017 16:03:07 +0100 Subject: [PATCH 05/10] Described how it works further --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 2aecde2..ebefb02 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,10 @@ Rate Limiter middleware. **How it works** The middleware restricts the number of requests from clients, based on their IP address. +It works by adding the clients IP address to the cache and count how many requests the clients can make during the Rate Limiter's lifespan and give back an HTTP 429(Too Many Requests) if the limit has been reached. The number of requests left will be reset when the defined timespan has been reached + +> Please take into consideration that multiple clients can be using the same IP address. eg. public wifi + ## 📦 Installation From 9ab9034b7f1d4544efdf641f06b5318a84332650 Mon Sep 17 00:00:00 2001 From: Mauran Muthiah Date: Thu, 16 Nov 2017 16:16:37 +0100 Subject: [PATCH 06/10] Aligning readme --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ebefb02..95a0868 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,10 @@ [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=https://github.com/nodes-vapor/gatekeeper)](http://clayallsopp.github.io/readme-score?url=https://github.com/nodes-vapor/gatekeeper) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nodes-vapor/gatekeeper/master/LICENSE) -Rate Limiter middleware. - -**How it works** - -The middleware restricts the number of requests from clients, based on their IP address. +Rate Limiter is a middleware that restricts the number of requests from clients, based on their IP address. It works by adding the clients IP address to the cache and count how many requests the clients can make during the Rate Limiter's lifespan and give back an HTTP 429(Too Many Requests) if the limit has been reached. The number of requests left will be reset when the defined timespan has been reached -> Please take into consideration that multiple clients can be using the same IP address. eg. public wifi +**Please take into consideration that multiple clients can be using the same IP address. eg. public wifi** ## 📦 Installation From 48bc1c81c88252bf46c1ea827e1f1da38a3cefa9 Mon Sep 17 00:00:00 2001 From: Mauran Muthiah Date: Fri, 17 Nov 2017 09:46:10 +0100 Subject: [PATCH 07/10] Renamed Rate Limiter to GateKeeper in description --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 95a0868..c72d22f 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=https://github.com/nodes-vapor/gatekeeper)](http://clayallsopp.github.io/readme-score?url=https://github.com/nodes-vapor/gatekeeper) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nodes-vapor/gatekeeper/master/LICENSE) -Rate Limiter is a middleware that restricts the number of requests from clients, based on their IP address. -It works by adding the clients IP address to the cache and count how many requests the clients can make during the Rate Limiter's lifespan and give back an HTTP 429(Too Many Requests) if the limit has been reached. The number of requests left will be reset when the defined timespan has been reached +GateKeeper is a middleware that restricts the number of requests from clients, based on their IP address. +It works by adding the clients IP address to the cache and count how many requests the clients can make during the GateKeepers defined lifespan and give back an HTTP 429(Too Many Requests) if the limit has been reached. The number of requests left will be reset when the defined timespan has been reached **Please take into consideration that multiple clients can be using the same IP address. eg. public wifi** @@ -24,10 +24,10 @@ Update your `Package.swift` file. ## Getting started 🚀 -`RateLimiter` has two configurable fields: the maximum rate and the cache to use. If you don't supply your own cache the limiter will create its own, in-memory cache. +`GateKeeper` has two configurable fields: the maximum rate and the cache to use. If you don't supply your own cache the limiter will create its own, in-memory cache. ```swift -let limiter = RateLimiter(rate: Rate(10, per: .minute)) +let limiter = GateKeeper(rate: Rate(10, per: .minute)) ``` ### Adding middleware @@ -37,14 +37,14 @@ You can add the middleware either globally or to a route group. #### `Sources/App/Config+Setup.swift` ```swift -import RateLimiter +import GateKeeper ``` ```swift public func setup() throws { // ... - addConfigurable(middleware: RateLimiter(rate: Rate(10, per: .minute)), name: "ratelimiter") + addConfigurable(middleware: GateKeeper(rate: Rate(10, per: .minute)), name: "gateKeeper") } ``` @@ -57,7 +57,7 @@ Add ratelimiter to the middleware array "error", "date", "file", - "ratelimiter" + "gateKeeper" ] ``` @@ -65,9 +65,9 @@ Add ratelimiter to the middleware array #### Adding Middleware to a Route Group ```Swift -let limiter = RateLimiter(rate: Rate(10, per: .minute)) +let gateKeeper = GateKeeper(rate: Rate(10, per: .minute)) -drop.group(limiter) { group in +drop.group(gateKeeper) { group in // Routes } ``` From 713a23e6166545bb5359919dc7a1f53e5955725f Mon Sep 17 00:00:00 2001 From: Mauran Muthiah Date: Fri, 17 Nov 2017 09:47:47 +0100 Subject: [PATCH 08/10] Fixed minor spelling error --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c72d22f..8476fe4 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ public func setup() throws { #### `Config/droplet.json` -Add ratelimiter to the middleware array +Add `gateKeeper` to the middleware array ```json "middleware": [ From 8802d164c6544de1fdcbf45e1923a8ede2ae41a2 Mon Sep 17 00:00:00 2001 From: Mauran Muthiah Date: Fri, 17 Nov 2017 09:54:37 +0100 Subject: [PATCH 09/10] Renamed limiter to gatekeeper in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8476fe4..8f7415e 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Update your `Package.swift` file. `GateKeeper` has two configurable fields: the maximum rate and the cache to use. If you don't supply your own cache the limiter will create its own, in-memory cache. ```swift -let limiter = GateKeeper(rate: Rate(10, per: .minute)) +let gateKeeper = GateKeeper(rate: Rate(10, per: .minute)) ``` ### Adding middleware From 9db99d6aa722b694d2f76d96cbdb55368833a443 Mon Sep 17 00:00:00 2001 From: Mauran Muthiah Date: Fri, 17 Nov 2017 10:29:00 +0100 Subject: [PATCH 10/10] Corrections on how gatekeeper is named --- README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8f7415e..8101e5d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ GateKeeper is a middleware that restricts the number of requests from clients, based on their IP address. It works by adding the clients IP address to the cache and count how many requests the clients can make during the GateKeepers defined lifespan and give back an HTTP 429(Too Many Requests) if the limit has been reached. The number of requests left will be reset when the defined timespan has been reached -**Please take into consideration that multiple clients can be using the same IP address. eg. public wifi** +**Please take into consideration that multiple clients can be using the same IP address. eg. public wifi** ## 📦 Installation @@ -24,10 +24,10 @@ Update your `Package.swift` file. ## Getting started 🚀 -`GateKeeper` has two configurable fields: the maximum rate and the cache to use. If you don't supply your own cache the limiter will create its own, in-memory cache. +`Gatekeeper` has two configurable fields: the maximum rate and the cache to use. If you don't supply your own cache the limiter will create its own, in-memory cache. ```swift -let gateKeeper = GateKeeper(rate: Rate(10, per: .minute)) +let gatekeeper = GateKeeper(rate: Rate(10, per: .minute)) ``` ### Adding middleware @@ -37,27 +37,27 @@ You can add the middleware either globally or to a route group. #### `Sources/App/Config+Setup.swift` ```swift -import GateKeeper +import Gatekeeper ``` ```swift public func setup() throws { // ... - addConfigurable(middleware: GateKeeper(rate: Rate(10, per: .minute)), name: "gateKeeper") + addConfigurable(middleware: GateKeeper(rate: Rate(10, per: .minute)), name: "gatekeeper") } ``` #### `Config/droplet.json` -Add `gateKeeper` to the middleware array +Add `gatekeeper` to the middleware array ```json "middleware": [ "error", "date", "file", - "gateKeeper" + "gatekeeper" ] ``` @@ -65,15 +65,14 @@ Add `gateKeeper` to the middleware array #### Adding Middleware to a Route Group ```Swift -let gateKeeper = GateKeeper(rate: Rate(10, per: .minute)) +let gatekeeper = Gatekeeper(rate: Rate(10, per: .minute)) -drop.group(gateKeeper) { group in +drop.group(gatekeeper) { group in // Routes } ``` - ### The `Rate.Interval` enumeration The currently implemented intervals are: