Skip to content

Commit 0b3cb65

Browse files
[HttpClient] fixes
1 parent ccb9084 commit 0b3cb65

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

ResponseInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function getContent(bool $throw = true): string;
7171
* - redirect_count - the number of redirects followed while executing the request
7272
* - redirect_url - the resolved location of redirect responses, null otherwise
7373
* - start_time - the time when the request was sent or 0.0 when it's pending
74+
* - http_method - the HTTP verb of the last request
7475
* - http_code - the last response code or 0 when it is not known yet
7576
* - error - the error message when the transfer was aborted, null otherwise
7677
* - data - the value of the "data" request option, null if not set

Test/HttpClientTestCase.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ public function testRedirects()
214214
$client = $this->getHttpClient();
215215
$response = $client->request('POST', 'http://localhost:8057/301', [
216216
'auth' => 'foo:bar',
217-
'body' => 'foo=bar',
217+
'body' => function () {
218+
yield 'foo=bar';
219+
},
218220
]);
219221

220222
$body = json_decode($response->getContent(), true);
@@ -236,7 +238,9 @@ public function testRedirects()
236238
'Content-Type: application/json',
237239
];
238240

239-
$filteredHeaders = array_intersect($expected, $response->getInfo('raw_headers'));
241+
$filteredHeaders = array_values(array_filter($response->getInfo('raw_headers'), function ($h) {
242+
return \in_array(substr($h, 0, 4), ['HTTP', 'Loca', 'Cont'], true) && 'Content-Encoding: gzip' !== $h;
243+
}));
240244

241245
$this->assertSame($expected, $filteredHeaders);
242246
}
@@ -261,6 +265,16 @@ public function testRelativeRedirects()
261265
public function testRedirect307()
262266
{
263267
$client = $this->getHttpClient();
268+
269+
$response = $client->request('POST', 'http://localhost:8057/307', [
270+
'body' => function () {
271+
yield 'foo=bar';
272+
},
273+
'max_redirects' => 0,
274+
]);
275+
276+
$this->assertSame(307, $response->getStatusCode());
277+
264278
$response = $client->request('POST', 'http://localhost:8057/307', [
265279
'body' => 'foo=bar',
266280
]);
@@ -297,7 +311,9 @@ public function testMaxRedirects()
297311
'Content-Type: application/json',
298312
];
299313

300-
$filteredHeaders = array_intersect($expected, $response->getInfo('raw_headers'));
314+
$filteredHeaders = array_values(array_filter($response->getInfo('raw_headers'), function ($h) {
315+
return \in_array(substr($h, 0, 4), ['HTTP', 'Loca', 'Cont'], true);
316+
}));
301317

302318
$this->assertSame($expected, $filteredHeaders);
303319
}
@@ -416,6 +432,7 @@ public function testPostCallback()
416432
$response = $client->request('POST', 'http://localhost:8057/post', [
417433
'body' => function () {
418434
yield 'foo';
435+
yield '';
419436
yield '=';
420437
yield '0123456789';
421438
},

0 commit comments

Comments
 (0)