From aaa3f86d222a2ea0eddc593f2fc7af639e57c32e Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Fri, 13 Nov 2026 00:23:13 +0100 Subject: [PATCH] Remove the unused default context merge from the stream transport The stream transport merged the http options of PHP's default stream context with its own options into $contextOptions and then never used the result: the context is created from its own options only, and a context passed to fopen() replaces the default one. Remove the dead code and document that the default context is not used. Co-Authored-By: Claude Opus 5.5 --- docs/classes/TransportInterface.md | 4 ++++ src/Transport/Stream.php | 9 --------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/docs/classes/TransportInterface.md b/docs/classes/TransportInterface.md index ffb364a5..a93f9c58 100644 --- a/docs/classes/TransportInterface.md +++ b/docs/classes/TransportInterface.md @@ -99,6 +99,10 @@ recorded requests are available for assertions. ## Options +The stream transport creates its own stream context for each request, so options set on PHP's default +context with `stream_context_set_default()` (a proxy, extra headers, …) are not used. Pass them with the +`transport.stream` option, which is merged into the context's `http` options, or with the options below. + `AbstractTransport::__construct($options = [])` accepts an array or `ArrayAccess`. Options are read with `getOption($key, $default)` and are transport-specific; the commonly used ones are: diff --git a/src/Transport/Stream.php b/src/Transport/Stream.php index ef468ba0..dd9f2fe1 100644 --- a/src/Transport/Stream.php +++ b/src/Transport/Stream.php @@ -139,15 +139,6 @@ public function request( $options[$key] = $value; } - // Get the current context options. - $contextOptions = stream_context_get_options(stream_context_get_default()); - - // Add our options to the currently defined options, if any. - $contextOptions['http'] = isset($contextOptions['http']) ? array_merge( - $contextOptions['http'], - $options - ) : $options; - // Create the stream context for the request. $streamOptions = [ 'http' => $options,