title: Set Response Status Code
body: <p>I have an API call for which I need to be able to run some checks and potentially return various status codes. I don't need custom views or anything, I just need to return the proper code. If the user hasn't passed proper credentials, I need to return a 401 status. If they haven't sent a supported request format, I need to return a 400 status.</p>
  
  <p>Because it's an API, all I really want to do is set the response status and exit with a simple, stupid message about why the request failed (probably using a <code>exit</code>). Just enough to get the job done, but I haven't been able to get this to work right. I've tried using PHP's <code>header()</code> and Cake's <code>$this-&gt;header()</code> (this is all in the controller), but although I get the exit message, the header shows a <code>200 OK</code> status.</p>
  
  <p>Using the code below, I get the message, but the header isn't set. What am I missing?</p>
  
  <pre><code>  if( !$this-&gt;auth_api() ) {
      header( '401 Not Authorized' );
      exit( 'Not authorized' );
    }
  </code></pre>