Add opt-in connect timeout support to SDK HTTP client (#56)#57
Open
chrismshea wants to merge 1 commit into
Open
Add opt-in connect timeout support to SDK HTTP client (#56)#57chrismshea wants to merge 1 commit into
chrismshea wants to merge 1 commit into
Conversation
Adds a new `connect_timeout` config key (default 0 = disabled) plumbed from Sdk config through Http to Guzzle RequestOptions::CONNECT_TIMEOUT. When unset/0, no CONNECT_TIMEOUT is passed, preserving prior behavior for existing consumers. The default api_request_timeout (30s) is unchanged. Also documents the timeout exception surface: a Guzzle connect/request timeout raises ConnectException/RequestException (not response-based), which is not represented by HttpException; consumers must catch the Guzzle transfer exceptions to handle timeouts. Refs #56
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds opt-in support for a Guzzle connect timeout to the SDK's HTTP client, and documents the timeout exception surface. Backward-compatible: the default request timeout (30s) is unchanged, and no connect timeout is applied unless one is configured.
Motivation: the SDK is called synchronously in user-facing contexts (e.g. the Magento extension's add-to-cart path). With only a total request timeout and no connect timeout, a slow or unreachable API can block a request and tie up web/PHP workers. This adds the fast-fail lever for the unreachable-host case, and clarifies why a timeout is not caught by
HttpException.Changes
Http.php— new$connectTimeoutconstructor argument (default0). When> 0, it is applied as GuzzleRequestOptions::CONNECT_TIMEOUT; when0, no connect timeout is set, preserving prior behavior for existing consumers.Sdk.php— newconnect_timeoutconfig key (default0), plumbed toHttp. Config docblock now documentsapi_request_timeout,connect_timeout, and the timeout exception surface.HttpTest.php— 2 new tests asserting the client receivesCONNECT_TIMEOUTonly when configured.Exception surface (documented in
Sdk.php)A Guzzle request/connect timeout raises
GuzzleHttp\Exception\ConnectException/RequestException, which is not response-based and is therefore not represented bySubscribePro\Exception\HttpException(which requires aResponseInterface). Consumers that must handle timeouts should catch the Guzzle transfer exceptions (or\RuntimeException) in addition toHttpException.Backward compatibility
api_request_timeoutremains30.connect_timeoutdefaults to0(disabled) — existing consumers see no behavior change.Httpconstructor arg is optional and last-positional.Testing
vendor/bin/phpunit tests/HttpTest.php→ 20/20 pass (18 existing + 2 new).connect_timeout=1fails at ~1.0s with aConnectException(confirming the connect timeout is applied).Related
Closes #56