13
13
class GuzzleHttpService extends AbstractCheck
14
14
{
15
15
protected $ url ;
16
+ protected $ method ;
17
+ protected $ body ;
16
18
protected $ headers ;
17
19
protected $ statusCode ;
18
20
protected $ content ;
@@ -25,14 +27,18 @@ class GuzzleHttpService extends AbstractCheck
25
27
* @param int $statusCode The response status code to check
26
28
* @param null $content The response content to check
27
29
* @param ClientInterface $guzzle Instance of guzzle to use
30
+ * @param string $method The method of the request
31
+ * @param mixed $body The body of the request (used for POST, PUT and DELETE requests)
28
32
*/
29
- public function __construct ($ url , array $ headers = array (), array $ options = array (), $ statusCode = 200 , $ content = null , ClientInterface $ guzzle = null )
33
+ public function __construct ($ url , array $ headers = array (), array $ options = array (), $ statusCode = 200 , $ content = null , ClientInterface $ guzzle = null , $ method = ' GET ' , $ body = null )
30
34
{
31
35
$ this ->url = $ url ;
32
36
$ this ->headers = $ headers ;
33
37
$ this ->options = $ options ;
34
38
$ this ->statusCode = $ statusCode ;
35
39
$ this ->content = $ content ;
40
+ $ this ->method = $ method ;
41
+ $ this ->body = $ body ;
36
42
37
43
if (!$ guzzle ) {
38
44
$ guzzle = new Client ();
@@ -46,7 +52,7 @@ public function __construct($url, array $headers = array(), array $options = arr
46
52
*/
47
53
public function check ()
48
54
{
49
- $ response = $ this ->guzzle ->get ($ this ->url , $ this ->headers , $ this ->options )->send ();
55
+ $ response = $ this ->guzzle ->createRequest ($ this ->method , $ this -> url , $ this ->headers , $ this -> body , $ this ->options )->send ();
50
56
51
57
if ($ this ->statusCode !== $ statusCode = $ response ->getStatusCode ()) {
52
58
return new Failure ("Status code {$ this ->statusCode } does not match {$ statusCode } in response from {$ this ->url }" );
0 commit comments