Skip to content

Commit

Permalink
Fix curl handler support http2 (#358)
Browse files Browse the repository at this point in the history
* Fix CurlHandler to support HTTP/2

* Bump version
  • Loading branch information
slavcodev committed Jul 19, 2019
1 parent 94d0bbd commit 7982131
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Security - in case of vulnerabilities.

## [Unreleased]

## [2.5.0] 2019-07-19

### Fixed
- [x] Fixed CurlHandler to support HTTP/2

## [2.4.0] 2019-07-01

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ final class Client

public const CURRENT_VERSION = 'v2.1';

public const SDK_VERSION = '2.4.0';
public const SDK_VERSION = '2.5.0';

private static $services = [
'authenticationOptions' => Services\AuthenticationOptionsService::class,
Expand Down
2 changes: 1 addition & 1 deletion src/Http/CurlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function __invoke(Request $request)
$headers = [];

// Extract the version and status from the first header
preg_match('#HTTP/(\d\.\d)\s(\d\d\d)\s(.*)#', array_shift($headerLines), $matches);
preg_match('#HTTP/(\d(?:\.\d)?)\s(\d\d\d)\s(.*)#', array_shift($headerLines), $matches);
array_shift($matches);
[$protocolVersion, $statusCode, $reasonPhrase] = $matches;

Expand Down
32 changes: 32 additions & 0 deletions tests/Http/CurlHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,38 @@ public function sendRequest($method, $url, $payload, $headers)
$this->assertSame(200, $response->getStatusCode());
}

/**
* @test
* @dataProvider provideValidRequests
*
* @param $method
* @param $url
* @param $payload
* @param $headers
*/
public function sendRequestHttp2($method, $url, $payload, $headers)
{
$request = $this->client->createRequest($method, $url, $payload, $headers);

$fakeBody = json_encode([], JSON_FORCE_OBJECT);
$fakeHeaders = "HTTP/2 200 OK\r\nContent-Type: application/json; charset=utf-8\r\n";

/** @var CurlSession|MockObject $session */
$session = $this->createMock(CurlSession::class);
$session->method('execute')->willReturn($fakeHeaders . $fakeBody);
$session->method('getInfo')->willReturn(strlen($fakeHeaders));

/** @var CurlHandler|MockObject $handler */
$handler = $this->createPartialMock(CurlHandler::class, ['createSession']);
$handler->method('createSession')->willReturn($session);

/** @var Response $response */
$response = call_user_func($handler, $request);

$this->assertInstanceOf(Response::class, $response);
$this->assertSame(200, $response->getStatusCode());
}

/**
* @test
*/
Expand Down

0 comments on commit 7982131

Please sign in to comment.