flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.62k stars 409 forks source link

How can we add headers to the response? #473

Closed dimitrihilverda closed 1 year ago

dimitrihilverda commented 2 years ago

This will set a header:

Flight::response()->header('X-Hook-Secret',$secret); I see that it is set: var_dump(Flight::response()->headers());

but then when I use Flight::json(response($activities, 'success')); and look at the headers, I used postman to test the endpoint, this header is not there...

Is there any way to add headers?

kuopassa commented 2 years ago

How about just regular PHP: header('X-Hook-Secret: something');

paxperscientiam commented 1 year ago

I tried with both static access and dynamic access; both cases work.

Try something really basic like this. See if the response headers come through.

<?PHP
require_once "./vendor/autoload.php";

Flight::response()->header('X-Hook-Secret', "DIRK");

Flight::route("*", function() {
    echo 69;
});

Flight::start();
dimitrihilverda commented 1 year ago

Ok, I found the problem, It works now as it should, somhow I had a file included that had a space before the <?php tag, that gave me an error in the logs that sayed, headers already send,,, My local setup was more strict than my production setup.

So not a bug or error on the Flight side, it was all on my side, thank you all!