Q:

How can I set the HTTP status code?

I'm trying to set a 404 HTTP status response code for an ajax controller action in a plugin.
Yii has a response object where the code can be set, but I can't find a way to access it from craft.

A:

I believe HeaderHelper::setHeader() is what you're looking for in the context of a plugin.

A:

HeaderHelper::setHeader(array('status' => 404));

A:

In Craft3, the correct way of setting HTTP status codes is 
Craft::$app->getResponse()->setStatusCode(404);

