Skip to content

Commit 6b15172

Browse files
committed
Merge branch 'curl-client-18'
2 parents fe5dd09 + 21885e9 commit 6b15172

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/Client.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,12 @@ private function createHeaders(RequestInterface $request, array $options)
254254
$curlHeaders = [];
255255
$headers = array_keys($request->getHeaders());
256256
foreach ($headers as $name) {
257-
if (strtolower($name) === 'content-length') {
257+
$header = strtolower($name);
258+
if ('expect' === $header) {
259+
// curl-client does not support "Expect-Continue", so dropping "expect" headers
260+
continue;
261+
}
262+
if ('content-length' === $header) {
258263
$values = [0];
259264
if (array_key_exists(CURLOPT_POSTFIELDS, $options)) {
260265
$values = [strlen($options[CURLOPT_POSTFIELDS])];
@@ -266,6 +271,11 @@ private function createHeaders(RequestInterface $request, array $options)
266271
$curlHeaders[] = $name . ': ' . $value;
267272
}
268273
}
274+
/*
275+
* curl-client does not support "Expect-Continue", but cURL adds "Expect" header by default.
276+
* We can not suppress it, but we can set it to empty.
277+
*/
278+
$curlHeaders []= 'Expect:';
269279

270280
return $curlHeaders;
271281
}

tests/ClientTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
namespace Http\Client\Curl\Tests;
3+
4+
use Http\Client\Curl\Client;
5+
use Zend\Diactoros\Request;
6+
7+
/**
8+
* Tests for Http\Client\Curl\Client
9+
*
10+
* @covers Http\Client\Curl\Client
11+
*/
12+
class ClientTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* "Expect" header should be empty
16+
*
17+
* @link https://github.com/php-http/curl-client/issues/18
18+
*/
19+
public function testExpectHeader()
20+
{
21+
$client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()
22+
->setMethods(['__none__'])->getMock();
23+
24+
$createHeaders = new \ReflectionMethod(Client::class, 'createHeaders');
25+
$createHeaders->setAccessible(true);
26+
27+
$request = new Request();
28+
29+
$headers = $createHeaders->invoke($client, $request, []);
30+
31+
static::assertContains('Expect:', $headers);
32+
}
33+
}

0 commit comments

Comments
 (0)