Return Cake/Http/Response without some headers

Hi, Ive made an API for a specific device and I need to return just a “1” or a “0”.
The problem is that when I do

$this->request = $this->request->withStringBody(‘1’);
return $this->request;

the response has headers that I can’t process on my device, like these ones:

  • ‘Content-Encoding’: ‘gzip’
  • ‘Content-Length’: 21 (it should be 1, I’m only returning a single character)
  • ‘Vary’
  • ‘Upgrade’

Ive tried using

$this->response = $this->response->withoutHeader(‘Content-Encoding’);

with no success since it removes the header from the response (at least is what I see using debug()) but the response that I get on postman has that Content-Encoding.

What am I doing wrong? Thanks in advance.

pd: I’m able to modify the header using

$this->response = $this->response->withHeader(‘Content-Encoding’, 0);
$this->response = $this->response->withHeader(‘Vary’, 0);
$this->response = $this->response->withHeader(‘Upgrade’, 0);

but I can’t remove it

This works fine for me inside one of my controllers:

$this->response = $this->getResponse()->withoutHeader('Content-Type');

Are those headers maybe added at a later point in time after the controller has already processed the request?
Check where your Content-Encoding is added. Maybe you need to write a custom Middleware which removes that header for you.

And are you sure your device accept http request / response? Not tcp or udp packets? If you can’t process them maybe you can skip them?

I just checked in my browser. With my example the returned html from my app just gets rendered as text.