1

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?

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.