dolejska-daniel / riot-api

Riot League of Legends & DataDragon API wrappers for PHP7 and PHP8.
GNU General Public License v3.0
113 stars 25 forks source link

SET_CACHE_RATELIMIT acting unexpectedly since v3.0 #40

Closed cohenu closed 5 years ago

cohenu commented 5 years ago

Describe the bug So we are in the middle of porting our system to V4 and we encountered an issue with the caching mechanism. After upgrading to v3.0.2 when ever SET_CACHE_RATELIMIT is set to true i get the following error

<br />
<b>Fatal error</b>:  Uncaught TypeError: Argument 4 passed to RiotAPI\LeagueAPI\Definitions\RateLimitControl::`registerLimits() must be of the type string or null, array given, called in /var/www/[redacted]/vendor/dolejska-daniel/riot-api/src/LeagueAPI/LeagueAPI.php on line 607 and defined in /var/www/[redacted]/vendor/dolejska-daniel/riot-api/src/LeagueAPI/Definitions/RateLimitControl.php:72
Stack trace:
#0 /var/www/[redacted]/vendor/dolejska-daniel/riot-api/src/LeagueAPI/LeagueAPI.php(607): RiotAPI\LeagueAPI\Definitions\RateLimitControl-&gt;registerLimits('[redacted]...', 'euw', '1416:summoner/s...', Array, Array)
#1 /var/www/[redacted]/vendor/dolejska-daniel/riot-api/src/LeagueAPI/LeagueAPI.php(1231): RiotAPI\LeagueAPI\LeagueAPI-&gt;RiotAPI\LeagueAPI\{closure}(Object(RiotAPI\LeagueAPI\LeagueAPI), 'https://euw1.ap...', 'ed56e305f3d5a59...', '/var/www/[redacted]...')
#2 /var/www/[redacted]/vendor/dolejska-daniel/riot-api/src/LeagueAPI/LeagueAPI.php(1071): RiotAPI\LeagueAPI\LeagueAPI-&gt;_afterCall('https://euw1.ap...', 'ed56e305f3d5a59...', ' in <b>/var/www/[redacted]/vendor/dolejska-daniel/riot-api/src/LeagueAPI/LeagueAPI.php</b> on line <b>1100</b><br />

(I redacted info that shouldn't be here :))

To Reproduce Steps to reproduce the behavior:

  1. Instantiate LeagueAPI with SET_CACHE_RATELIMIT set to true (We are using a custom redis ICacheprovider implementation but from my tests the failure occurs before it even reaches that point)
  2. Make any request to Riot API

Expected behavior The library should return the relevant data.

Screenshots Not relevant

Server (please complete the following information):

Additional context After playing around with the code I found out that the headers are returned in a weird format. here is the result from var_dump straight from the call function before the ICacheProvider is even contacted (This is ran with an empty cache so that everything is returned from Riot API).

array(10) {
  ["Content-Type"]=>
  array(1) {
    [0]=>
    string(30) "application/json;charset=utf-8"
  }
  ["Date"]=>
  array(1) {
    [0]=>
    string(30) "Sun, 13 Jan 2019  18:18:07 GMT"
  }
  ["Vary"]=>
  array(1) {
    [0]=>
    string(15) "Accept-Encoding"
  }
  ["X-App-Rate-Limit"]=>
  array(1) {
    [0]=>
    string(16) "500:10,30000:600"
  }
  ["X-App-Rate-Limit-Count"]=>
  array(1) {
    [0]=>
    string(10) "1:10,5:600"
  }
  ["X-Method-Rate-Limit"]=>
  array(1) {
    [0]=>
    string(7) "2000:60"
  }
  ["X-Method-Rate-Limit-Count"]=>
  array(1) {
    [0]=>
    string(4) "2:60"
  }
  ["X-Riot-Edge-Trace-Id"]=>
  array(1) {
    [0]=>
    string(36) "14c2268a-8cda-4ab2-9f00-bda3c6e4d46b"
  }
  ["Content-Length"]=>
  array(1) {
    [0]=>
    string(3) "298"
  }
  ["Connection"]=>
  array(1) {
    [0]=>
    string(10) "keep-alive"
  }
}

Notice how instead of a clear string its a nested array and registerLimits expects the headers to be strings and not arrays.

dolejska-daniel commented 5 years ago

Hello and thanks for the bug report! This happend when I switched to Guzzle.. Dunno how it slipped between my fingers 😄. You can pull v3.0.3 and should be okay!

cohenu commented 5 years ago

No problem, thanks for the fast response 😄