steampixel / simplePHPRouter

This is a simple and small single class PHP router that can handel the whole url routing for your project.
MIT License
406 stars 117 forks source link

Managing Header code before the server is sending the default header response #48

Closed ghost closed 3 years ago

ghost commented 3 years ago

hi all,

Love your router, basic but do his job very well - Congrats!

Just a question: Since your route already manage when an url isn't found in the route (error404 that we have to manage ourself), and you already manage error 503 (method not allowed)... Couldn't be awesome to manage all headers too? Per example be able the get the Header Code so we can display a proper error page (ex: error 400 Bad Request, etc.)?

thx in advance !

steampixel commented 3 years ago

Hey @laboxmedia , this router is just a basic concept. I don't want to add more complexity to it.

Another reason is that response headers can be set by the whole server stack. Maybe you have an Nginx Server which proxies your requests to an Apache server which will call your PHP app. Each of this layers can add individual response headers to the outgoing stream. A "Bad Request" for example can appear on each of this layers.

Yet another reason this router does not set headers by default is that you maybe do not want to set a 404 header if a page was not found. Maybe you want to set a 301 header for redirecting the request. Maybe you want to be silent about the status. Your app will decide.

Also you have to define first what a bad request is. The router cannot know which request are "bad". Your app will decide this.

Was this answer helpful? Don't know if I understand your question completely.

ghost commented 3 years ago

thank you for the response, we'll try doing it by doing ErrorDocument into our htaccess then!