AFAIK it should work & out of the box there is no differences, and no reason to not send that header in publish.
Could you please reverify all the code changes are moved to publish. If yes can you please set header at page component level and verify.
I checked that the code is published and I tried to generate a minimal example.
While removing unnecessary stuff from the page I noticed that after a given threshhold the header is generated.
This buy just removing HTML (no code). I reach a point where if I remove a simple
the page is correctly delivered with the header, if I insert it back the header is no more there.
Could this be related to HTTP chunking? If yes how can I disable it to debug?
If you want to add a header to the HTTP response, you should do that before you output any character of the response body. Depending on the implementation of the servlet engine it might work also if you have added some characters to the response body, but this will work only due to the great heart of some developer, who built it in.