SSE response support #162

Open
opened 2026-04-10 14:43:43 +00:00 by 0riginaln0 · 2 comments
0riginaln0 commented 2026-04-10 14:43:43 +00:00 (Migrated from github.com)

Axum already has Server-Sent Events support.
https://docs.rs/axum/latest/axum/response/sse/struct.Event.html
https://github.com/tokio-rs/axum/blob/main/examples/sse/src/main.rs

Can we somehow export its functionality to Lua?

I'm not sure about the exact API.

Axum already has Server-Sent Events support. https://docs.rs/axum/latest/axum/response/sse/struct.Event.html https://github.com/tokio-rs/axum/blob/main/examples/sse/src/main.rs Can we somehow export its functionality to Lua? I'm not sure about the exact API.
0riginaln0 commented 2026-04-10 15:07:20 +00:00 (Migrated from github.com)

Maybe this API will work.

local server = require("http").server.new()

-- Coroutine-based generator  
local function sse_coroutine()  
    local counter = 0  
    while counter <= 100 do  
        counter = counter + 1  
        local data = string.format("data: Random number: %d\n\n", math.random(1, 100))  
        coroutine.yield(data)  
        -- await/sleep
    end  
end  
  
server:get("/sse-coroutine", function(request, response)  
    response:set_header("Content-Type", "text/event-stream")  
    response:set_header("Cache-Control", "no-cache")  
    response:set_header("Connection", "keep-alive")  
      
    local co = coroutine.create(sse_coroutine)  
    return co  
end)
Maybe this API will work. ```lua local server = require("http").server.new() -- Coroutine-based generator local function sse_coroutine() local counter = 0 while counter <= 100 do counter = counter + 1 local data = string.format("data: Random number: %d\n\n", math.random(1, 100)) coroutine.yield(data) -- await/sleep end end server:get("/sse-coroutine", function(request, response) response:set_header("Content-Type", "text/event-stream") response:set_header("Cache-Control", "no-cache") response:set_header("Connection", "keep-alive") local co = coroutine.create(sse_coroutine) return co end) ```
ElhamAryanpur commented 2026-05-03 17:08:45 +00:00 (Migrated from github.com)

I absolutely forgot to add this one, thank you! I'll look into it

I absolutely forgot to add this one, thank you! I'll look into it
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ArkForgeLabs/Astra#162
No description provided.