Headers/Status
Response Headers
To get/set a response header in Mack you just access the response method in Mack::Controller as if it were a Hash:
class UsersController
include Mack::Controller
def show
response['Content-Type'] = 'text/html'
response['Content-Type'] # => 'text/html'
end
end
Response Status
It's easy to set the status of your response:
class UsersController
include Mack::Controller
def show
response.status = 404
render(:text, 'Not Found')
end
end
In this example the status of the response will be set to 404. The above could also be written like this:
class UsersController
include Mack::Controller
def show
render(:text, 'Not Found', :status => 404)
end
end
Both the render and the redirect_to methods in Mack::Controller take an optional Hash that can contain a :status option.