diff --git a/README.md b/README.md index 7b25cb9..13c5739 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ -# Rate Limiter - -#### CONTENTS OF THIS FILE +CONTENTS OF THIS FILE --------------------- * Introduction * Features @@ -13,84 +11,104 @@ * Maintainer(s) * Change Log -##### Introduction ------------------- -*Rate Limiter* module can be useful when to disallow concurrent web service -access to the application. -##### Features +INTRODUCTION +------------ + + * Rate Limiter* module can be useful when to disallow concurrent web service + access to the application. + + +FEATURES +-------- + This module exposes a "Rate Limiting" service for RestAPI web service calls. + This service features: -* Define number of concurrent allowed hits in a given time window. -* Rate limiting on each request. -* Limit hits based on IP address. -* IP White listing option. -* Defines a separate cache bin to store the rate limiter hits and counts. -* Exportable configurations. -* Supports `Accept` HTTP headers and Drupal recommended `_format` calls. - -##### Requirements ------------------- -* RESTful Web Services -* Serialization - -##### Installation ------------------- + * Define number of concurrent allowed hits in a given time window. + * Rate limiting on each request. + * Limit hits based on IP address. + * IP White listing option. + * Defines a separate cache bin to store the rate limiter hits and counts. + * Exportable configurations. + * Supports `Accept` HTTP headers and Drupal recommended `_format` calls. + + +REQUIREMENTS +------------ + + * RESTful Web Services + * Serialization + + +INSTALLATION +------------ + Follow [installation] -(https://www.drupal.org/documentation/install/modules-themes/modules-8) +(https://www.drupal.org/documentation/install/modules-themes/modules-8) guide to install the module into the site. -##### Configuration ------------------- -Navigate to Configuration >> Web services >> Rate Limiter Configuration + +CONFIGURATION +------------- + +Navigate to Configuration >> Web services >> Rate Limiter Configuration (admin/config/services/rate-limiter). + The configuration has two segments. -* General Configuration -* Access Rules + * General Configuration: It has basic configurations to enable the module with + allowed request limit in an allowed time frame. + An optional message can be shown when the limit is reached. + * Access Rules: It has two option to enable rate limiting service for all + web-service request or based on IP. + If IP based rate limiting is selected then there is an IP based + white listing option available. -**General Configuration** has basic configurations to enable the module with -allowed request limit in an allowed time frame. -An optional message can be shown when the limit is reached. -**Access Rules** has two option to enable rate limiting service for all -web-service request or based on IP. -If IP based rate limiting is selected then there is an IP based -white listing option available. +ASSUMPTIONS +----------- -##### Assumptions ------------------- The following points were assumed while developing the module. -1. Every Web-service call either have "Accept" header or "_format" query string. -2. The Rate Limiting service will only work on requests with -"application/json", "application/xml" and "application/hal+json" -`Accept` headers -or `_format` query string with "json", "hal_json" and "xml" values. -3. Command line requests and "text/html" requests are considered as normal -drupal requests to the site not as Service calls. - -##### Caution ------------------- -This module stores all it's rate limiter hit counts in Drupal's cache. -So clearing cache will remove all the items. + 1. Every Web-service call either have "Accept" header or "_format" query + string. + 2. The Rate Limiting service will only work on requests with + "application/json", "application/xml" and "application/hal+json" + `Accept` headers or `_format` query string with "json", "hal_json" and + "xml" values. + 3. Command line requests and "text/html" requests are considered as normal + drupal requests to the site not as Service calls. + + +CAUTION +------- + +This module stores all it's rate limiter hit counts in Drupal's cache. +So clearing cache will remove all the items. Assumed that in a production environment caches are not cleared more often. -##### Future Improvements ------------------- -* Enable *Bearer Token* based Rate limiting service with [OAuth2 Server] -(https://www.drupal.org/project/oauth2_server) module. -* Based on Feature Requests more improvements. -* Integration test suite for testing Rate Limiting service. - -##### Maintainer(s) ------------------- -###### Current maintainer -* Aneek Mukhopadhyay (aneek) - https://www.drupal.org/u/aneek - -##### Change Log ------------------- -* 8.x-1.0 - Initial version created. -* 8.x-1.1 - Improvements over "Accept header based routing". - * Based on [#2501221](https://www.drupal.org/node/2501221) - now supports `_format` to determine a service request - and Response. + +FUTURE IMPROVEMENTS +------------------- + + * Enable *Bearer Token* based Rate limiting service with [OAuth2 Server] + (https://www.drupal.org/project/oauth2_server) module. + * Based on Feature Requests more improvements. + * Integration test suite for testing Rate Limiting service. + + +MAINTAINER(S) +------------- + +Current maintainers: + * Aneek Mukhopadhyay (aneek) - https://www.drupal.org/u/aneek + + +CHANGE LOG +---------- + + * 8.x-1.0 - Initial version created. + * 8.x-1.1 - Improvements over "Accept header based routing". + * Based on [#2501221](https://www.drupal.org/node/2501221) + now supports `_format` to determine a service request + and Response. diff --git a/src/Form/RateLimiterConfigForm.php b/src/Form/RateLimiterConfigForm.php index 4dd4be5..7568a64 100644 --- a/src/Form/RateLimiterConfigForm.php +++ b/src/Form/RateLimiterConfigForm.php @@ -192,5 +192,4 @@ class RateLimiterConfigForm extends ConfigFormBase { ->save(); parent::submitForm($form, $form_state); } - } diff --git a/src/RateLimitManager.php b/src/RateLimitManager.php index ba27e38..c3ea417 100644 --- a/src/RateLimitManager.php +++ b/src/RateLimitManager.php @@ -313,5 +313,4 @@ class RateLimitManager implements RateLimitManagerInterface { return new Response($message, Response::HTTP_TOO_MANY_REQUESTS, $headers); } } - } diff --git a/src/RateLimitManagerInterface.php b/src/RateLimitManagerInterface.php index 944da84..eea02f2 100644 --- a/src/RateLimitManagerInterface.php +++ b/src/RateLimitManagerInterface.php @@ -80,5 +80,4 @@ interface RateLimitManagerInterface { * The proper response after checking the accept header. */ public function respond(); - } diff --git a/src/RateLimitMiddleware.php b/src/RateLimitMiddleware.php index ebab5c5..8f17176 100644 --- a/src/RateLimitMiddleware.php +++ b/src/RateLimitMiddleware.php @@ -59,5 +59,4 @@ class RateLimitMiddleware implements HttpKernelInterface { } return $this->app->handle($request, $type, $catch); } - } diff --git a/src/Tests/RateLimiterTest.php b/src/Tests/RateLimiterTest.php index 2070971..55bab91 100644 --- a/src/Tests/RateLimiterTest.php +++ b/src/Tests/RateLimiterTest.php @@ -61,5 +61,4 @@ class RateLimiterTest extends WebTestBase { $this->assertText(t('Allowed Requests field is required.'), t('Allowed Requests field is validated')); $this->assertText(t('Allowed time window field is required.'), t('Allowed time window field is validated')); } - }