I am attempting to add a custom header within a Laravel(8) response called X-Custom which works, but it places it at the top of the header stack as such:
HTTP/1.1 200 OK
Date: Mon, 01 Nov 2021 10:58:44 GMT
Server: Apache/2.4.29 (Ubuntu)
X-Custom: 8675309
Cache-Control: no-cache, private
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
Access-Control-Allow-Origin: *
Content-Length: 15
Content-Type: text/html; charset=UTF-8
Content is here
With low memory devices (an ATTiny85) the earliest header I manage to receive is X-RateLimit-Remaining: 59. So to get the X-Custom header I ideally need it to go on the bottom of the whole stack like so:
HTTP/1.1 200 OK
Date: Mon, 01 Nov 2021 10:58:44 GMT
Server: Apache/2.4.29 (Ubuntu)
Cache-Control: no-cache, private
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
Access-Control-Allow-Origin: *
Content-Length: 15
Content-Type: text/html; charset=UTF-8
X-Custom: 8675309
Content is here
From what I can see Laravel returns the various headers from different files rather than all in one go so I think a simple sort is out of the question.
Is sticking a header on the end achieveable within Laravel's means?
Edit: On Chris Haas's comment it made me realise I don't need the headers as I'm only looking for one. Middleware was a dead end as it all seems to run just prior to all these Laravel headers being pushed. I have discovered if I comment out $this->sendHeaders() within symfony/http-foundation/Response.php::send() , it clears it up to this:
HTTP/1.1 200 OK
Date: Tue, 02 Nov 2021 01:21:29 GMT
Server: Apache/2.4.29 (Ubuntu)
X-Custom: 8675309
Content-Length: 15
Content-Type: text/html; charset=UTF-8
Content is here
I think this is as clean as I can get it from Laravel. This may be enough to get these devices working but in the effort to properly answer this question I am going to see what I can do from the Apache side.
Edit2: Following this answer https://stackoverflow.com/a/24941636/3417896 I can remove the Content-Type header by setting header("Content-type:") at the same place I'm commenting out sendHeaders(), resulting in this:
HTTP/1.1 200 OK
Date: Tue, 02 Nov 2021 02:23:45 GMT
Server: Apache/2.4.29 (Ubuntu)
X-Custom: 8675309
Content-Length: 15
Content is here
Ok now the Content-length I think remains in Apache. I saw another answer on how to remove it from php here https://stackoverflow.com/a/31563538/3417896, but it adds another header in its place.