dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.33k stars 1.25k forks source link

the request Rate limiting for per route #1651

Closed zjsy closed 5 years ago

zjsy commented 5 years ago
Q A
Bug? yes
New Feature? no
Framework Lumen
Framework version 5.7.8
Package version 2.2.3
PHP version 7.2.10

Actual Behaviour

when i request not same route, counted in total

Expected Behaviour

request not same route not counted in total

Steps to Reproduce

my route code

$api->version('v1', [
    'namespace' => 'App\Http\Controllers\Wxapp\V1',
    'prefix' => 'wxapp',
//    'domain' => env('API_DOMAIN'),
    'middleware' => [
//        'cors',
       // 'serializer',
        //'serializer:array', // if you want to remove data wrap
        'api.throttle',
    ],
    // each route have a limit of 20 of 1 minutes
    'limit' => 2, 'expires' => 1,
], function ($api) {
    $api->get('test1', 'UtilsController@test1');
    $api->get('test2', 'UtilsController@test2');
})

Within one minute frist request curl http://domain/wxapp/test1 success is ok second request curlhttp://domain/wxapp/test1 success is ok third request curlhttp://domain/wxapp/test1 faied is ok but when i frist request curl http://domain/wxapp/test1 faied no This is not the result I want

Possible Solutions

If you have any ideas on how to solve the issue, add them here, otherwise you can omit this part.

zjsy commented 5 years ago

i see /src/Http/RateLimit/Handler.php

 101       } elseif ($limit > 0 || $expires > 0) {
 102            $this->throttle = new Route(['limit' => $limit, 'expires' => $expires]);
 103           $this->keyPrefix = sha1($request->path());

define keyPrefix ,why cache not use; i dont know,i am just a newbie

zjsy commented 5 years ago

After upgrading lumen is ok

zjsy commented 5 years ago

刚刚debug的时候,忽然发现又走到了/src/Http/RateLimit/Handler.php,发现竟然用上了$this->keyPrefix,好奇怪,对了一下dingo的版本竟然又是一样的