-
-
Notifications
You must be signed in to change notification settings - Fork 454
[4.x] Add a default cURL HTTP client #1589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fa5145d
Add a default cURL HTTP client
cleptric aa2c5d2
Add `http_ssl_verify_peer ` option
cleptric 6d81fc0
Add tests for new options
cleptric dec5282
Refactor HttpClient and Transport options handling
cleptric 4c6ea44
Fix $$
cleptric 22c9409
Add argument doc
cleptric 8c601ea
Merge branch '4.x' into curl-http-client
cleptric e3561fc
Mark ClientBuilder as internal
cleptric fd39f7e
Mark Result as final
cleptric fd4f85b
Cleanup HttpClient
cleptric b60d22c
Clean up Response
cleptric 5b475dc
Add HttpTransport test
cleptric 859b789
CS
cleptric e1c176b
Improve header parsing
cleptric 40be49e
Add more ClientBuilder tests
cleptric a4ab6e0
Add case-insensitive header handling
cleptric 6731f38
Refactor Http::getRequestHeaders
cleptric a2f5594
Add CURLOPT_HEADEROPT=CURLHEADER_SEPARATE for proxy connections
cleptric c9b3a2d
Refactor response header parsing
cleptric cb00c86
CS
cleptric 681bee0
Merge branch '4.x' into curl-http-client
cleptric 51a5b58
Cleanup
cleptric File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,36 +4,36 @@ | |
|
||
namespace Sentry; | ||
|
||
use Http\Discovery\Psr17FactoryDiscovery; | ||
use Psr\Log\LoggerInterface; | ||
use Sentry\HttpClient\HttpClientFactory; | ||
use Sentry\HttpClient\HttpClient; | ||
use Sentry\HttpClient\HttpClientInterface; | ||
use Sentry\Serializer\PayloadSerializer; | ||
use Sentry\Serializer\RepresentationSerializerInterface; | ||
use Sentry\Serializer\SerializerInterface; | ||
use Sentry\Transport\DefaultTransportFactory; | ||
use Sentry\Transport\TransportFactoryInterface; | ||
use Sentry\Transport\HttpTransport; | ||
use Sentry\Transport\TransportInterface; | ||
|
||
/** | ||
* The default implementation of {@link ClientBuilderInterface}. | ||
* A configurable builder for Client objects. | ||
* | ||
* @author Stefano Arlandini <[email protected]> | ||
* @internal | ||
*/ | ||
final class ClientBuilder implements ClientBuilderInterface | ||
final class ClientBuilder | ||
{ | ||
/** | ||
* @var Options The client options | ||
*/ | ||
private $options; | ||
|
||
/** | ||
* @var TransportFactoryInterface|null The transport factory | ||
* @var TransportInterface The transport | ||
*/ | ||
private $transportFactory; | ||
private $transport; | ||
|
||
/** | ||
* @var TransportInterface|null The transport | ||
* @var HttpClientInterface The HTTP client | ||
cleptric marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
private $transport; | ||
private $httpClient; | ||
|
||
/** | ||
* @var SerializerInterface|null The serializer to be injected in the client | ||
|
@@ -68,127 +68,97 @@ final class ClientBuilder implements ClientBuilderInterface | |
public function __construct(Options $options = null) | ||
{ | ||
$this->options = $options ?? new Options(); | ||
|
||
$this->httpClient = $this->options->getHttpClient() ?? new HttpClient($this->sdkIdentifier, $this->sdkVersion); | ||
$this->transport = $this->options->getTransport() ?? new HttpTransport( | ||
$this->options, | ||
$this->httpClient, | ||
new PayloadSerializer($this->options), | ||
$this->logger | ||
); | ||
cleptric marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @param array<string, mixed> $options The client options, in naked array form | ||
*/ | ||
public static function create(array $options = []): ClientBuilderInterface | ||
public static function create(array $options = []): ClientBuilder | ||
{ | ||
return new self(new Options($options)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getOptions(): Options | ||
{ | ||
return $this->options; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setSerializer(SerializerInterface $serializer): ClientBuilderInterface | ||
public function setSerializer(SerializerInterface $serializer): ClientBuilder | ||
{ | ||
$this->serializer = $serializer; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setRepresentationSerializer(RepresentationSerializerInterface $representationSerializer): ClientBuilderInterface | ||
public function setRepresentationSerializer(RepresentationSerializerInterface $representationSerializer): ClientBuilder | ||
{ | ||
$this->representationSerializer = $representationSerializer; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setLogger(LoggerInterface $logger): ClientBuilderInterface | ||
public function setLogger(LoggerInterface $logger): ClientBuilder | ||
{ | ||
$this->logger = $logger; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setSdkIdentifier(string $sdkIdentifier): ClientBuilderInterface | ||
public function setSdkIdentifier(string $sdkIdentifier): ClientBuilder | ||
{ | ||
$this->sdkIdentifier = $sdkIdentifier; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setSdkVersion(string $sdkVersion): ClientBuilderInterface | ||
public function setSdkVersion(string $sdkVersion): ClientBuilder | ||
{ | ||
$this->sdkVersion = $sdkVersion; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setTransportFactory(TransportFactoryInterface $transportFactory): ClientBuilderInterface | ||
public function getTransport(): TransportInterface | ||
{ | ||
$this->transportFactory = $transportFactory; | ||
|
||
return $this; | ||
return $this->transport; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getClient(): ClientInterface | ||
public function setTransport(TransportInterface $transport): ClientBuilder | ||
{ | ||
$this->transport = $this->transport ?? $this->createTransportInstance(); | ||
$this->transport = $transport; | ||
|
||
return new Client($this->options, $this->transport, $this->sdkIdentifier, $this->sdkVersion, $this->serializer, $this->representationSerializer, $this->logger); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Creates a new instance of the transport mechanism. | ||
*/ | ||
private function createTransportInstance(): TransportInterface | ||
public function getHttpClient(): HttpClientInterface | ||
{ | ||
if (null !== $this->transport) { | ||
return $this->transport; | ||
} | ||
return $this->httpClient; | ||
} | ||
|
||
$transportFactory = $this->transportFactory ?? $this->createDefaultTransportFactory(); | ||
public function setHttpClient(HttpClientInterface $httpClient): ClientBuilder | ||
{ | ||
$this->httpClient = $httpClient; | ||
|
||
return $transportFactory->create($this->options); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Creates a new instance of the {@see DefaultTransportFactory} factory. | ||
*/ | ||
private function createDefaultTransportFactory(): DefaultTransportFactory | ||
public function getClient(): ClientInterface | ||
cleptric marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$streamFactory = Psr17FactoryDiscovery::findStreamFactory(); | ||
$httpClientFactory = new HttpClientFactory( | ||
null, | ||
null, | ||
$streamFactory, | ||
null, | ||
return new Client( | ||
$this->options, | ||
$this->transport, | ||
$this->sdkIdentifier, | ||
$this->sdkVersion | ||
); | ||
|
||
return new DefaultTransportFactory( | ||
$streamFactory, | ||
Psr17FactoryDiscovery::findRequestFactory(), | ||
$httpClientFactory, | ||
$this->sdkVersion, | ||
$this->serializer, | ||
$this->representationSerializer, | ||
$this->logger | ||
); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.