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_chunked.lua | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/civetweb/test/page_keep_alive_chunked.lua (limited to 'src/civetweb/test/page_keep_alive_chunked.lua') diff --git a/src/civetweb/test/page_keep_alive_chunked.lua b/src/civetweb/test/page_keep_alive_chunked.lua new file mode 100644 index 00000000..28ac7d12 --- /dev/null +++ b/src/civetweb/test/page_keep_alive_chunked.lua @@ -0,0 +1,66 @@ +-- Set keep_alive. The return value specifies if this is possible at all. +canKeepAlive = mg.keep_alive(true) +now = os.date("!%a, %d %b %Y %H:%M:%S") + +-- 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: " .. now .. " GMT\r\n") +mg.write("Cache-Control: no-cache\r\n") +mg.write("Last-Modified: " .. now .. " GMT\r\n") +if not canKeepAlive then + mg.write("Connection: close\r\n") + mg.write("\r\n") + mg.write("Keep alive not possible!") + return +end +if mg.request_info.http_version ~= "1.1" then + -- wget will use HTTP/1.0 and Connection: keep-alive, so chunked transfer is not possible + mg.write("Connection: close\r\n") + mg.write("\r\n") + mg.write("Chunked transfer is only possible for HTTP/1.1 requests!") + mg.keep_alive(false) + return +end + +-- use chunked encoding (http://www.jmarshall.com/easy/http/#http1.1c2) +mg.write("Cache-Control: max-age=0, must-revalidate\r\n") +--mg.write("Cache-Control: no-cache\r\n") +--mg.write("Cache-Control: no-store\r\n") +mg.write("Connection: keep-alive\r\n") +mg.write("Transfer-Encoding: chunked\r\n") +mg.write("\r\n") + +-- function to send a chunk +function send(str) + local len = string.len(str) + mg.write(string.format("%x\r\n", len)) + mg.write(str.."\r\n") +end + +-- send the chunks +send("") +send("Civetweb Lua script chunked transfer test page") +send("\n") + +fileCnt = 0 +if lfs then + send("Files in " .. lfs.currentdir()) + send('\n\n') + send('\n') + for f in lfs.dir(".") do + local at = lfs.attributes(f); + if at then + send('\n') + end + fileCnt = fileCnt + 1 + end + send("
nametypesize
' .. f .. '' .. at.mode .. '' .. at.size .. '
\n") +end + +send(fileCnt .. " entries (" .. now .. " GMT)\n") +send("") +send("") + +-- end +send("") -- cgit v1.2.3