-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Description
- Laravel Version: 7.0.8
- PHP Version: 7.4
Description:
Whenever you are trying to use the ->withToken('token-here')
method, instead of replacing existing token, the Authorization
header is now changed to array
instead of string
and the are now 2 tokens in there.
Steps To Reproduce:
// $client - instance of PendingRequest
$client = Illuminate\Support\Facades\Http::withHeaders([
'User-Agent' => 'Not the user agent you were looking for'
])->withToken('SuperAmazingTokenForOneTypeOfOperations', 'Bearer');
// Do something which requires the original token
// And here is the problem, Authorization header is not
// a string anymore but rather an array containing two tokens
$client->withToken('ThisIsNEWTokenForDifferentOperation', 'Bearer')->post();
You might think that the following piece of code will overwrite (i know it won't and i am sure you knew that already) the Authorization
header if called explicitly:
$client->withHeaders(['Authorization' => 'Bearer ThisIsNEWTokenForDifferentOperation'])
It simply appends new token to the now array
(i think because of the array_merge_recursive
function call inside the withHeaders
method)
Use Case:
I have a wrapper (Client
class) for the api service, since most of the times the configuration is the same across all of the routes of the api, i've made a class which simply returns me the PendingRequest
class instance, so i can call different methods without recreation of the Http
'helper'.
Suggestions:
- Replace old token with new one by default
- Allow us to access headers so we can edit them prior the request
- Maybe provide a couple of methods to manipulate the existing headers (like:
resetToken()
)