0

I searched for a way to remove headers in API response, but the already answered questions are talking about an specific Header and not any of them, like: Laravel remove header values from API response

In my scenario the APIs are called from a device which doesn't care about Date , Host , X-Powered-By, ... and so many other headers in API resposne. in my case response size is so important, my data is 100B but my Headers are about 350B!!

so my question is how to edit or remove Headers in Laravel or PHP, is there anyway to modify these Headers and just keep the really needed ones.

Amas
  • 1,040
  • 1
  • 8
  • 22
  • Have you tried to investigate Response file itself? – Akbar Apr 26 '19 at 10:10
  • @SomeDev what do you mean exactly? if you mean the way response is created in laravel, its common way `response()->json` – Amas Apr 26 '19 at 10:15
  • I mean, dig into Laravel response files, how laravel generate responses. There maybe ways you customize them for your personal use – Akbar Apr 26 '19 at 10:21
  • @SomeDev thats exactly my question! is there anyway? if so how is that – Amas Apr 26 '19 at 10:24
  • https://stackoverflow.com/questions/13483781/http-response-with-no-http-header – Akbar Apr 26 '19 at 10:45
  • I haven't tried yet, I think it is against specification too. What are you doing that even bytes are important for? Maybe there are other ways that let you not touch standart response – Akbar Apr 26 '19 at 10:48
  • device uses 2G internet connection. so reducing response size may help to make connection faster – Amas Apr 26 '19 at 10:59

1 Answers1

4

Your web server (Nginx or Apache) is probably adding a few headers as well, not sure if you can disable all of them though. You need to edit the server/site config file for your web server to accomplish this since they are added after the php script has been executed.

KFoobar
  • 1,367
  • 10
  • 17