Skip to content

Commit

Permalink
Merge branch 'symfony:7.1' into 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
faizanakram99 committed Apr 22, 2024
2 parents 7d26392 + 02c1e3c commit c0f6d90
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 51 deletions.
11 changes: 10 additions & 1 deletion src/Symfony/Component/HttpClient/CachingHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\HttpClient;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Component\HttpClient\Response\ResponseStream;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -31,7 +33,7 @@
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class CachingHttpClient implements HttpClientInterface, ResetInterface
class CachingHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
{
use HttpClientTrait;

Expand Down Expand Up @@ -142,4 +144,11 @@ public function reset(): void
$this->client->reset();
}
}

public function setLogger(LoggerInterface $logger): void
{
if ($this->client instanceof LoggerAwareInterface) {
$this->client->setLogger($logger);
}
}
}
11 changes: 10 additions & 1 deletion src/Symfony/Component/HttpClient/EventSourceHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\HttpClient;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\Chunk\ServerSentEvent;
use Symfony\Component\HttpClient\Exception\EventSourceException;
use Symfony\Component\HttpClient\Response\AsyncContext;
Expand All @@ -25,7 +27,7 @@
* @author Antoine Bluchet <soyuka@gmail.com>
* @author Nicolas Grekas <p@tchwork.com>
*/
final class EventSourceHttpClient implements HttpClientInterface, ResetInterface
final class EventSourceHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
{
use AsyncDecoratorTrait, HttpClientTrait {
AsyncDecoratorTrait::withOptions insteadof HttpClientTrait;
Expand Down Expand Up @@ -156,4 +158,11 @@ public function request(string $method, string $url, array $options = []): Respo
}
});
}

public function setLogger(LoggerInterface $logger): void
{
if ($this->client instanceof LoggerAwareInterface) {
$this->client->setLogger($logger);
}
}
}
11 changes: 10 additions & 1 deletion src/Symfony/Component/HttpClient/RetryableHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\HttpClient;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\Response\AsyncContext;
use Symfony\Component\HttpClient\Response\AsyncResponse;
Expand All @@ -27,7 +28,7 @@
*
* @author Jérémy Derussé <jeremy@derusse.com>
*/
class RetryableHttpClient implements HttpClientInterface, ResetInterface
class RetryableHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
{
use AsyncDecoratorTrait;

Expand Down Expand Up @@ -163,6 +164,14 @@ public function request(string $method, string $url, array $options = []): Respo
});
}

public function setLogger(LoggerInterface $logger): void
{
$this->logger = $logger;
if ($this->client instanceof LoggerAwareInterface) {
$this->client->setLogger($logger);
}
}

private function getDelayFromHeader(array $headers): ?int
{
if (null !== $after = $headers['retry-after'][0] ?? null) {
Expand Down
11 changes: 10 additions & 1 deletion src/Symfony/Component/HttpClient/ThrottlingHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\HttpClient;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\RateLimiter\LimiterInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
Expand All @@ -19,7 +21,7 @@
/**
* Limits the number of requests within a certain period.
*/
class ThrottlingHttpClient implements HttpClientInterface, ResetInterface
class ThrottlingHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
{
use DecoratorTrait {
reset as private traitReset;
Expand Down Expand Up @@ -48,4 +50,11 @@ public function reset(): void
$this->traitReset();
$this->rateLimiter->reset();
}

public function setLogger(LoggerInterface $logger): void
{
if ($this->client instanceof LoggerAwareInterface) {
$this->client->setLogger($logger);
}
}
}
11 changes: 10 additions & 1 deletion src/Symfony/Component/HttpClient/UriTemplateHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Symfony\Component\HttpClient;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Symfony\Contracts\Service\ResetInterface;

class UriTemplateHttpClient implements HttpClientInterface, ResetInterface
class UriTemplateHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
{
use DecoratorTrait;

Expand Down Expand Up @@ -62,6 +64,13 @@ public function withOptions(array $options): static
return $clone;
}

public function setLogger(LoggerInterface $logger): void
{
if ($this->client instanceof LoggerAwareInterface) {
$this->client->setLogger($logger);
}
}

/**
* @return \Closure(string $url, array $vars): string
*/
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
private readonly string $tokenType = 'Bearer',
) {
$this->regex = sprintf(
'/^%s([a-zA-Z0-9\-_\+~\/\.]+)$/',
'/^%s([a-zA-Z0-9\-_\+~\/\.]+=*)$/',
'' === $this->tokenType ? '' : preg_quote($this->tokenType).'\s+'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
use Symfony\Component\Security\Http\AccessToken\AccessTokenExtractorInterface;
use Symfony\Component\Security\Http\AccessToken\AccessTokenHandlerInterface;
use Symfony\Component\Security\Http\AccessToken\HeaderAccessTokenExtractor;
use Symfony\Component\Security\Http\Authenticator\AccessTokenAuthenticator;
use Symfony\Component\Security\Http\Authenticator\FallbackUserLoader;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
Expand Down Expand Up @@ -159,4 +160,31 @@ public function testAuthenticateWithFallbackUserLoader()

$this->assertEquals('test', $passport->getUser()->getUserIdentifier());
}

/**
* @dataProvider provideAccessTokenHeaderRegex
*/
public function testAccessTokenHeaderRegex(string $input, ?string $expectedToken)
{
// Given
$extractor = new HeaderAccessTokenExtractor();
$request = Request::create('/test', 'GET', [], [], [], ['HTTP_AUTHORIZATION' => $input]);

// When
$token = $extractor->extractAccessToken($request);

// Then
$this->assertEquals($expectedToken, $token);
}

public function provideAccessTokenHeaderRegex(): array
{
return [
['Bearer token', 'token'],
['Bearer mF_9.B5f-4.1JqM', 'mF_9.B5f-4.1JqM'],
['Bearer d3JvbmdfcmVnZXhwX2V4bWFwbGU=', 'd3JvbmdfcmVnZXhwX2V4bWFwbGU='],
['Bearer Not Valid', null],
['Bearer (NotOK123)', null],
];
}
}

0 comments on commit c0f6d90

Please sign in to comment.