Don't inflate http response by default

This commit is contained in:
the-djmaze 2026-10-23 16:45:02 +02:00
parent 0204ca48ee
commit b5c1be34c2

View file

@ -39,23 +39,28 @@ class Response
$this->request_uri = $request_uri; $this->request_uri = $request_uri;
$this->final_uri = $request_uri; $this->final_uri = $request_uri;
$this->status = (int) $status; $this->status = (int) $status;
if (\function_exists('gzinflate') && isset($this->headers['content-encoding'])
&& (false !== \stripos($this->headers['content-encoding'], 'gzip'))) {
$this->body = \gzinflate(\substr($body, 10, -4));
if (false === $this->body) {
$err = \error_get_last() ?: ['message' => 'gzinflate failed'];
throw new \RuntimeException("{$err['message']} for {$request_uri}");
}
} else {
$this->body = $body; $this->body = $body;
} }
}
function __get($k) function __get($k)
{ {
return \property_exists($this, $k) ? $this->$k : null; return \property_exists($this, $k) ? $this->$k : null;
} }
public function decoded()/*: string|false*/
{
$body = $this->body;
if (\function_exists('gzinflate') && isset($this->headers['content-encoding'])
&& (false !== \stripos($this->headers['content-encoding'], 'gzip'))) {
$body = \gzinflate(\substr($body, 10, -4));
if (false === $body) {
$err = \error_get_last() ?: ['message' => 'gzinflate failed'];
throw new \RuntimeException("{$err['message']} for {$request_uri}");
}
}
return $body;
}
/** /**
* returns string, array or null * returns string, array or null
*/ */