diff --git a/classes/phing/tasks/ext/HttpRequestTask.php b/classes/phing/tasks/ext/HttpRequestTask.php index 70944365bd..5d5623d951 100644 --- a/classes/phing/tasks/ext/HttpRequestTask.php +++ b/classes/phing/tasks/ext/HttpRequestTask.php @@ -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 * @@ -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 * @@ -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 @@ -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.'); + } + } } }