@@ -79,7 +79,7 @@ public function wait(?ResponseInterface $pendingResponse, float $maxDuration = n
7979
8080 if ([, $ promise ] = $ this ->promisePool [$ response ] ?? null ) {
8181 unset($ this ->promisePool [$ response ]);
82- $ promise ->resolve ($ this ->createPsr7Response ( $ response , true ));
82+ $ promise ->resolve (self :: createPsr7Response ( $ this ->responseFactory , $ this -> streamFactory , $ this -> client , $ response , true ));
8383 }
8484 } catch (\Exception $ e ) {
8585 if ([$ request , $ promise ] = $ this ->promisePool [$ response ] ?? null ) {
@@ -114,9 +114,17 @@ public function wait(?ResponseInterface $pendingResponse, float $maxDuration = n
114114 return $ count ;
115115 }
116116
117- public function createPsr7Response (ResponseInterface $ response , bool $ buffer = false ): Psr7ResponseInterface
117+ public static function createPsr7Response (ResponseFactoryInterface $ responseFactory , StreamFactoryInterface $ streamFactory , HttpClientInterface $ client , ResponseInterface $ response , bool $ buffer ): Psr7ResponseInterface
118118 {
119- $ psrResponse = $ this ->responseFactory ->createResponse ($ response ->getStatusCode ());
119+ $ responseParameters = [$ response ->getStatusCode ()];
120+
121+ foreach ($ response ->getInfo ('response_headers ' ) as $ h ) {
122+ if (11 <= \strlen ($ h ) && '/ ' === $ h [4 ] && preg_match ('#^HTTP/\d+(?:\.\d+)? (?:\d\d\d) (.+)# ' , $ h , $ m )) {
123+ $ responseParameters [1 ] = $ m [1 ];
124+ }
125+ }
126+
127+ $ psrResponse = $ responseFactory ->createResponse (...$ responseParameters );
120128
121129 foreach ($ response ->getHeaders (false ) as $ name => $ values ) {
122130 foreach ($ values as $ value ) {
@@ -129,11 +137,11 @@ public function createPsr7Response(ResponseInterface $response, bool $buffer = f
129137 }
130138
131139 if ($ response instanceof StreamableInterface) {
132- $ body = $ this -> streamFactory ->createStreamFromResource ($ response ->toStream (false ));
140+ $ body = $ streamFactory ->createStreamFromResource ($ response ->toStream (false ));
133141 } elseif (!$ buffer ) {
134- $ body = $ this -> streamFactory ->createStreamFromResource (StreamWrapper::createResource ($ response , $ this -> client ));
142+ $ body = $ streamFactory ->createStreamFromResource (StreamWrapper::createResource ($ response , $ client ));
135143 } else {
136- $ body = $ this -> streamFactory ->createStream ($ response ->getContent (false ));
144+ $ body = $ streamFactory ->createStream ($ response ->getContent (false ));
137145 }
138146
139147 if ($ body ->isSeekable ()) {
0 commit comments