title: Response::json() sending html instead of json
body: <p>Using Laravel 4, <code>return Response::json(array('foo' =&gt; 'bar'))</code> used in one controller will return actual <code>application/json</code>, whereas in another controller, for another action, it will return <code>text/html</code>. Both actions are called via Ajax.</p>
  
  <p>In the <strong>faulty controller</strong>, I tried to force the content-type with this snippet:</p>
  
  <pre><code>[...]
  
  $response = Response::json($data);
  $response-&gt;header('Content-Type', 'application/json');
  $response-&gt;header('Content-Foo', 'Bar'); // test if additional headers are really set
  Log::info($response);
  return $response;
  </code></pre>
  
  <p>... while <strong>working controller</strong> returns correct Json response with:</p>
  
  <pre><code>return Response::json($data);
  </code></pre>
  
  <p>In both, <code>$data</code> is an array (tested).</p>
  
  <p><strong>Logged response</strong> from the faulty controller is:</p>
  
  <pre><code>HTTP/1.0 200 OK
  Cache-Control: no-cache
  Content-Foo:   Bar
  Content-Type:  application/json
  Date:          Wed, 17 Sep 2014 10:55:03 GMT
  </code></pre>
  
  <p>But <strong>received response</strong> (in Firebug / DevTools) is:</p>
  
  <pre><code>Connection  Keep-Alive
  Content-Type    text/html
  Date    Wed, 17 Sep 2014 10:55:03 GMT
  Keep-Alive  timeout=5, max=93
  Server  Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/0.9.8y DAV/2 PHP/5.5.3
  Transfer-Encoding   chunked
  X-Powered-By    PHP/5.5.3
  </code></pre>
  
  <p>I tried to directly return <code>Response::json(array('foo' =&gt; 'bar'))</code> at the beginning of the faulty controller action but it still sends the response as <code>text/html</code>.</p>
  
  <p>I would like to know why would the content-type switch from <code>application/json</code> to <code>text/html</code> for no reason? And why the mock header isn't in the received response?</p>
  
  <h2><strong>-- EDIT --</strong></h2>
  
  <p>The problem seems to be located around the validator.</p>
  
  <pre><code>public function faultyAction()
  {
      if(!Request::ajax()) App::abort(405);
  
      $validator = Validator::make(
          array('trackfile' =&gt; Input::file('trackfile')),
          array('trackfile' =&gt; 'required|audio')); // audio is a custom validator
  
      if($validator-&gt;fails())
      {
          Log::info('validation failed!');
          return Response::json(array('code' =&gt; 1, 'message' =&gt; 'File validation has failed.'));
      } 
      else
      {
          Log::info('validation passed!');
          return Response::json(array('code' =&gt; 0, 'filename' =&gt; 'test'));
      }
  }
  </code></pre>
  
  <p>... returns <code>text/html</code> response while <strong>validation passed</strong>.</p>
  
  <pre><code>public function faultyAction()
  {
      if(!Request::ajax()) App::abort(405);
  
      $validator = Validator::make(
          array('trackfile' =&gt; Input::file('trackfile')),
          array('trackfile' =&gt; 'required|audio')); // audio is a custom validator
  
      return Response::json(array('code' =&gt; 0, 'filename' =&gt; 'test'));
  }
  </code></pre>
  
  <p>... returns <code>application/json</code>.</p>
  
  <p><strong>How comes the same response is returned with different content-type depending on where it is called in the code?</strong></p>
  
  <p>May it come from <code>$validator-&gt;fails()</code> (even if nothing seems to alter the headers or to print something in the Laravel's <code>Validator.php</code> code)? </p>