Skip to content

Commit

Permalink
Fix phingofficial#824: allow the status-code to be checked in http-re…
Browse files Browse the repository at this point in the history
…quest task. (phingofficial#826)
  • Loading branch information
manarth authored and mrook committed Jun 11, 2018
1 parent b286e1f commit 4043609
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion classes/phing/tasks/ext/HttpRequestTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class HttpRequestTask extends HttpTask
*/
protected $responseRegex = '';

/**
* Holds the regular expression that should match the response code
*
* @var string
*/
protected $responseCodeRegex = '';

/**
* Whether to enable detailed logging
*
Expand Down Expand Up @@ -81,6 +88,16 @@ public function setResponseRegex($regex)
$this->responseRegex = $regex;
}

/**
* Sets the response code regex
*
* @param string $regex
*/
public function setResponseCodeRegex($regex)
{
$this->responseCodeRegex = $regex;
}

/**
* Sets whether to enable detailed logging
*
Expand Down Expand Up @@ -192,7 +209,7 @@ private function isHeaderSet($headerName, $headerValue)
}

/**
* Checks whether response body matches the given regexp
* Checks whether response body or status-code matches the given regexp
*
* @param HTTP_Request2_Response $response
* @return void
Expand All @@ -210,5 +227,16 @@ protected function processResponse(HTTP_Request2_Response $response)
$this->log('The response body matched the provided regex.');
}
}

if ($this->responseCodeRegex !== '') {
$matches = [];
preg_match($this->responseCodeRegex, $response->getStatus(), $matches);

if (count($matches) === 0) {
throw new BuildException('The received response status-code did not match the given regular expression');
} else {
$this->log('The response status-code matched the provided regex.');
}
}
}
}

0 comments on commit 4043609

Please sign in to comment.