Headers not properly set with response->setContentType |
Any ideas why setting headers like this doesn't work:
Code: $this->response->setContentType('text/event-stream') but using like this works? Code: header('Content-Type: text/event-stream') I've build the following MWE running on a fresh install of CI4's appstarter: PHP Code: <?php PHP Code: <?php To my surprise, with LiteSpeed or OpenLiteSpeed server "/not-working" returns the correct headers Any ideas why both "$this->response->setContentType('text/event-stream');" and "$this->response->setHeader('Content-Type', 'text/event-stream')?" does not in my controller? TIA.
Not send json raw. Send your response as "return $this->response->setJson(...)"
You not applied response in controller, this not work.
Simple CI 4 project for beginners codeigniter-expenses
(09-28-2023, 09:37 AM)ozornick Wrote: Not send json raw. Send your response as "return $this->response->setJson(...)" Unfortunately using "setJSON()" as suggested returns "application/json" headers instead of "text/event-stream". That's because it calls "formatBody()". I'm trying to implement some Server-Sent Events (SSE), so it requires "text/event-stream" headers for receiving plain text data that ends with "\n\n". I figure out how to make it works with all tested servers (Apache, nginx, LiteSpeed). Thanks for the tip. PHP Code: public function working() |
Welcome Guest, Not a member yet? Register Sign In |