1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 01:34:31 +02:00

Fix issue in WireHttp where it didn't reset the HTTP code description text (like "OK" or "Page Not Found" or "Internal Server Error" between multiple requests.

This commit is contained in:
Ryan Cramer
2022-06-24 13:30:22 -04:00
parent 5d3367846e
commit 818b78a42c

View File

@@ -778,10 +778,10 @@ class WireHttp extends Wire {
if($result === false) { if($result === false) {
$this->error[] = curl_error($curl); $this->error[] = curl_error($curl);
$this->httpCode = 0; $this->setHttpCode(0, '');
} else { } else {
$this->setResponseHeaderValues($responseHeaders); $this->setResponseHeaderValues($responseHeaders);
$this->httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); $this->setHttpCode(curl_getinfo($curl, CURLINFO_HTTP_CODE));
} }
curl_close($curl); curl_close($curl);
@@ -1027,7 +1027,9 @@ class WireHttp extends Wire {
} }
$result = curl_exec($curl); $result = curl_exec($curl);
if($result) $this->httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if($result) {
$this->setHttpCode(curl_getinfo($curl, CURLINFO_HTTP_CODE));
}
if($result === false) $this->error[] = curl_error($curl); if($result === false) $this->error[] = curl_error($curl);
curl_close($curl); curl_close($curl);
@@ -1343,8 +1345,7 @@ class WireHttp extends Wire {
if(strlen($httpText)) $httpText = preg_replace('/[^-_.;() a-zA-Z0-9]/', ' ', $httpText); if(strlen($httpText)) $httpText = preg_replace('/[^-_.;() a-zA-Z0-9]/', ' ', $httpText);
} }
$this->httpCode = (int) $httpCode; $this->setHttpCode((int) $httpCode, $httpText);
$this->httpCodeText = $httpText;
if($this->httpCode >= 400 && isset($this->httpCodes[$this->httpCode])) { if($this->httpCode >= 400 && isset($this->httpCodes[$this->httpCode])) {
$this->error[] = $this->httpCodes[$this->httpCode]; $this->error[] = $this->httpCodes[$this->httpCode];
@@ -1745,6 +1746,7 @@ class WireHttp extends Wire {
$this->responseHeader = array(); $this->responseHeader = array();
$this->responseHeaders = array(); $this->responseHeaders = array();
$this->httpCode = 0; $this->httpCode = 0;
$this->httpCodeText = '';
$this->error = array(); $this->error = array();
} }
@@ -1792,6 +1794,19 @@ class WireHttp extends Wire {
return $this->httpCode; return $this->httpCode;
} }
/**
* Set http response code and text
*
* @param int $code
* @param string $text
*
*/
protected function setHttpCode($code, $text = '') {
if(empty($text)) $text = isset($this->httpCodes[$code]) ? $this->httpCodes[$code] : '?';
$this->httpCode = $code;
$this->httpCodeText = $text;
}
/** /**
* Return array of all possible HTTP codes as (code => description) * Return array of all possible HTTP codes as (code => description)
* *