@@ -79,7 +79,7 @@ public function wait(?ResponseInterface $pendingResponse, float $maxDuration = n
79
79
80
80
if ([, $ promise ] = $ this ->promisePool [$ response ] ?? null ) {
81
81
unset($ this ->promisePool [$ response ]);
82
- $ promise ->resolve ($ this ->createPsr7Response ( $ response , true ));
82
+ $ promise ->resolve (self :: createPsr7Response ( $ this ->responseFactory , $ this -> streamFactory , $ this -> client , $ response , true ));
83
83
}
84
84
} catch (\Exception $ e ) {
85
85
if ([$ request , $ promise ] = $ this ->promisePool [$ response ] ?? null ) {
@@ -114,9 +114,17 @@ public function wait(?ResponseInterface $pendingResponse, float $maxDuration = n
114
114
return $ count ;
115
115
}
116
116
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
118
118
{
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 );
120
128
121
129
foreach ($ response ->getHeaders (false ) as $ name => $ values ) {
122
130
foreach ($ values as $ value ) {
@@ -129,11 +137,11 @@ public function createPsr7Response(ResponseInterface $response, bool $buffer = f
129
137
}
130
138
131
139
if ($ response instanceof StreamableInterface) {
132
- $ body = $ this -> streamFactory ->createStreamFromResource ($ response ->toStream (false ));
140
+ $ body = $ streamFactory ->createStreamFromResource ($ response ->toStream (false ));
133
141
} elseif (!$ buffer ) {
134
- $ body = $ this -> streamFactory ->createStreamFromResource (StreamWrapper::createResource ($ response , $ this -> client ));
142
+ $ body = $ streamFactory ->createStreamFromResource (StreamWrapper::createResource ($ response , $ client ));
135
143
} else {
136
- $ body = $ this -> streamFactory ->createStream ($ response ->getContent (false ));
144
+ $ body = $ streamFactory ->createStream ($ response ->getContent (false ));
137
145
}
138
146
139
147
if ($ body ->isSeekable ()) {
0 commit comments