# HG changeset patch # User Kim Alvefur # Date 1564592106 -7200 # Node ID fd054689a64cf2d0c1628b81db27d77ed3ef0b60 # Parent 915e32d5a14795f0bd434bc789fa1d6dd5e82548 mod_http_stats_stream: Use existing header preparation This allows the CORS support in mod_http to work. diff -r 915e32d5a147 -r fd054689a64c mod_http_stats_stream/mod_http_stats_stream.lua --- a/mod_http_stats_stream/mod_http_stats_stream.lua Tue Jul 30 02:07:13 2019 +0200 +++ b/mod_http_stats_stream/mod_http_stats_stream.lua Wed Jul 31 18:55:06 2019 +0200 @@ -1,4 +1,5 @@ local statsman = require "core.statsmanager"; +local http = require "net.http.server"; local json = require "util.json"; local sessions = {}; @@ -13,16 +14,14 @@ response.on_destroy = updates_client_closed; - response.conn:write(table.concat({ - "HTTP/1.1 200 OK"; - "Content-Type: text/event-stream"; - "X-Accel-Buffering: no"; -- For nginx maybe? - ""; - "event: stats-full"; - "data: "..json.encode(statsman.get_stats()); - ""; - ""; - }, "\r\n")); + response.headers.content_type = "text/event-stream"; + response.headers.x_accel_buffering = "no"; -- for nginx maybe? + local resp = http.prepare_header(response); + table.insert(resp, "event: stats-full\r\n"); + table.insert(resp, "data: "); + table.insert(resp, json.encode(statsman.get_stats())); + table.insert(resp, "\r\n\r\n"); + response.conn:write(table.concat(resp)); sessions[response] = request; return true;