Answers.Body: <p>I have finally found out that you need to set the RAW on the Response.</p>
  <pre><code>$this-&gt;response-&gt;format = Response::FORMAT_RAW;
  </code></pre>
  <p>So you can overwrite the response format with your own headers.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-17T18:15:23.300Z
Answers.LastActivityDate: 2022-11-17T18:15:23.300Z
Answers.UserDisplayName: Tudor-Radu Barbu
Body: <p>I'm trying to listen to SSE events from a controller action.</p>
  <p>I am setting the headers in the controller action with:</p>
  <pre><code>  Craft::$app-&gt;response-&gt;headers
        -&gt;set('Content-Type: text/event-stream')
        -&gt;set('Cache-Control: no-cache');
  </code></pre>
  <p>The EventSource listener always gives me:</p>
  <pre><code>EventSource's response has a MIME type (&quot;text/html&quot;) that is not &quot;text/event-stream&quot;. Aborting the connection.
  </code></pre>
  <p>Checking the URL (controller action URL) manually, you can see indeed that the headers are &quot;text/html&quot; and I cannot change them.</p>
  <p>What is a good way to send SSE events from CraftCMS?</p>
  
Tags: <plugin-development><controller><craft4>
Title: Using EventStream doesn't work because MimeType from Controller Action is always text/html
ThreadText: # Using EventStream doesn't work because MimeType from Controller Action is always text/html
  
  (Asked by: username_0 on 2022-11-17)
  
  I'm trying to listen to SSE events from a controller action.
  
  I am setting the headers in the controller action with:
  
  ```
    Craft::$app->response->headers
        ->set('Content-Type: text/event-stream')
        ->set('Cache-Control: no-cache');
  
  ```
  
  The EventSource listener always gives me:
  
  ```
  EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection.
  
  ```
  
  Checking the URL (controller action URL) manually, you can see indeed that the headers are "text/html" and I cannot change them.
  
  What is a good way to send SSE events from CraftCMS?
  
  **Tags:** plugin-development, controller, craft4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-11-17. Score: 1 | Accepted answer
  
  I have finally found out that you need to set the RAW on the Response.
  
  ```
  $this->response->format = Response::FORMAT_RAW;
  
  ```
  
  So you can overwrite the response format with your own headers.
  
  
  ---
  
  