From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. 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 00000000..d869ce46 --- /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