Skip to content

Commit 2e09b2e

Browse files
committed
feature FriendsOfPHP#24 Make status code available on consul response (Gufran)
This PR was merged into the 2.0-dev branch. Discussion ---------- Make status code available on consul response Since this is a library for HTTP API, status code is crucial to maintain compatibility with specifications like PSR7 and other abstractions. This changeset makes status code available on consul response. Commits ------- 08a412a Make status code available on consul response
2 parents dcfdef3 + 08a412a commit 2e09b2e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Consul/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private function doRequest($method, $url, $options)
9595
throw new ClientException($message, $response->getStatusCode());
9696
}
9797

98-
return new ConsulResponse($response->getHeaders(), (string)$response->getBody());
98+
return new ConsulResponse($response->getHeaders(), (string)$response->getBody(), $response->getStatusCode());
9999
}
100100

101101
private function formatResponse(Response $response)

Consul/ConsulResponse.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ class ConsulResponse
66
{
77
private $headers;
88
private $body;
9+
private $status;
910

10-
public function __construct($headers, $body)
11+
public function __construct($headers, $body, $status = 200)
1112
{
1213
$this->headers = $headers;
1314
$this->body = $body;
15+
$this->status = $status;
1416
}
1517

1618
public function getHeaders()
@@ -23,6 +25,11 @@ public function getBody()
2325
return $this->body;
2426
}
2527

28+
public function getStatusCode()
29+
{
30+
return $this->status;
31+
}
32+
2633
public function json()
2734
{
2835
return json_decode($this->body, true);

0 commit comments

Comments
 (0)