From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/civetweb/test/page_keep_alive.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/civetweb/test/page_keep_alive.lua (limited to 'src/civetweb/test/page_keep_alive.lua') diff --git a/src/civetweb/test/page_keep_alive.lua b/src/civetweb/test/page_keep_alive.lua new file mode 100644 index 000000000..d869ce46f --- /dev/null +++ b/src/civetweb/test/page_keep_alive.lua @@ -0,0 +1,34 @@ +-- Set keep_alive. The return value specifies if this is possible at all. +canKeepAlive = mg.keep_alive(true) + +if canKeepAlive then + -- Create the entire response in a string variable first. Content-Length will be set to the length of this string. + reply = [[ + +

This is a Lua script supporting html keep-alive with the + CivetWeb web server. +

+

It works by setting the Content-Length header field properly. + + ]] +else + reply = "Keep alive not possible!" +end + +-- First send the http headers +mg.write("HTTP/1.1 200 OK\r\n") +mg.write("Content-Type: text/html\r\n") +mg.write("Date: " .. os.date("!%a, %d %b %Y %H:%M:%S") .. " GMT\r\n") +mg.write("Cache-Control: no-cache\r\n") + +if canKeepAlive then + mg.write("Content-Length: " .. tostring(string.len(reply)) .. "\r\n") + mg.write("Connection: keep-alive\r\n") +else + mg.write("Connection: close\r\n") +end +mg.write("\r\n") + +-- Finally send the content +mg.write(reply) + -- cgit v1.2.3