Where is a correct place to add http headers in MVC applications: in controller or in view?
(Technically it is possible to do either in controller or view, but it is not clear for me what solution better suites with MVC model)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The purpose of the MVC pattern is to offer a clear separation of duties. The view handles presentation, the controller handles events, and the model provides the business logic. (I realize many web frameworks don’t follow the MVC pattern exactly. Django, for example, calls itself a MVT (or something like that)).
Therefore, since HTTP headers are a presentation detail, they should go in the view. A well-written MVC app would allow you to have non-web-based views (such as a desktop version) using the same controller and model. Putting the headers in the controller would break this clear separation.