Bläddra i källkod

Add some local tests to the git repo

bel2125 7 år sedan
förälder
incheckning
80353abe03
7 ändrade filer med 109 tillägg och 20 borttagningar
  1. 32 0
      test/donate.html
  2. 10 0
      test/linux_stderr.cgi
  3. 4 4
      test/page.lua
  4. 8 0
      test/page1.lua
  5. 49 10
      test/page2.lua
  6. 3 3
      test/page3.lua
  7. 3 3
      test/page4.lua

+ 32 - 0
test/donate.html

@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+
+<body>
+
+<a href="https://github.com/civetweb/civetweb">CivetWeb web server</a> maintenance (<a href="https://github.com/civetweb/civetweb/issues/523">#523</a>):
+
+<p>
+<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
+<input type="hidden" name="cmd" value="_s-xclick">
+<input type="hidden" name="hosted_button_id" value="88ZLXZ6U77GJU">
+<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
+<img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
+</form>
+</p>
+
+<p>
+<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=88ZLXZ6U77GJU">
+<img src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" alt="donate">
+</a>
+</p>
+
+<p>
+<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=88ZLXZ6U77GJU">
+<img src="https://img.shields.io/badge/Donate-PayPal-green.svg" alt="donate">
+</a>
+</p>
+
+</body>
+
+</html>
+

+ 10 - 0
test/linux_stderr.cgi

@@ -0,0 +1,10 @@
+#!/bin/sh
+
+printf "Content-Type: text/plain\r\n"
+printf "\r\n"
+
+echo "This is a shell script called by CGI:"
+tree / 1>&2
+echo
+set
+

+ 4 - 4
test/page.lua

@@ -1,9 +1,9 @@
 mg.write("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")
 
-mg.write([[
-<html><body>
-<p>This is another example of a Lua script, creating a web page served by the
-<a href="https://github.com/civetweb/civetweb/">CivetWeb web server</a>.
+mg.write([[<html><body>
+<p>This is Lua script example 1, served by the
+<a href="https://github.com/civetweb/civetweb">CivetWeb web server</a>,
+version ]] .. mg.version .. [[.
 </p><p>
 The following features are available:
 <ul>

+ 8 - 0
test/page1.lua

@@ -0,0 +1,8 @@
+loc = string.gsub(mg.request_info.request_uri, "page1.lua", "page.lua")
+
+mg.write("HTTP/1.0 301 Moved Permanently\r\n")
+mg.write("Location: " .. loc .. "\r\n")
+mg.write("Content-Length: 0\r\n")
+mg.write("Connection: close\r\n")
+mg.write("\r\n")
+

+ 49 - 10
test/page2.lua

@@ -2,9 +2,9 @@ mg.write("HTTP/1.0 200 OK\r\n")
 mg.write("Content-Type: text/html\r\n")
 mg.write("\r\n")
 mg.write([[<html><body>
-
-<p>This is another example of a Lua server page, served by
-<a href="https://github.com/civetweb/civetweb">CivetWeb web server</a>.
+<p>This is Lua script example 2, served by the
+<a href="https://github.com/civetweb/civetweb">CivetWeb web server</a>,
+version ]] .. mg.version .. [[.
 </p><p>
 The following features are available:
 <ul>
@@ -12,7 +12,9 @@ The following features are available:
 
 function print_if_available(tab, name)
   if tab then
-    mg.write("<li>" .. name .. "</li>\n")
+    mg.write("<li>" .. name .. " available</li>\n")
+  else
+    mg.write("<li>" .. name .. " not available</li>\n")
   end
 end
 
@@ -61,31 +63,68 @@ print_if_available(connect, "connect function")
 mg.write("<li>server options</li>\n")
 recurse(mg.get_option())
 
+-- Print some data from random generators
+if mg.uuid then
+  mg.write("<li>random data</li>\n")
+  local t = {GUID = mg.uuid(), random = mg.random()}
+  recurse(t)
+end
+
+-- Print loaded packages known to Lua
+if package and (type(package.loaded)=="table") then
+  if #package.loaded > 0 then
+    mg.write("<li>loaded packages</li>\n")
+    recurse(package.loaded)
+  else
+    mg.write("<li>loaded packages: none</li>\n")
+  end
+end
+
+-- Print preloaded packages known to Lua
+if xml then
+  mg.write("<li>xml</li>\n")
+  recurse(xml)
+end
+
+-- Current date/time
 mg.write("</ul></p>\n");
 mg.write("<p> Today is " .. os.date("%A") .. "</p>\n");
 
+-- Request content
+mg.write("\n<hr/>\n")
 l = mg.request_info.content_length
 if l then
   mg.write("<p>Content-Length = "..l..":<br>\n<pre>\n")
   mg.write(mg.read())
   mg.write("\n</pre>\n</p>\n")
+else
+  mg.write("<p>not request content available</p>\n")
 end
 
+-- Directory listing
+mg.write("\n<hr/>\n")
 mg.write("<p>\n");
-
- if lfs then
+if not lfs then
+  mg.write("lfs not available\n")
+else
   mg.write("Files in " .. lfs.currentdir())
   mg.write("\n<ul>\n")
+  local cnt = 0
   for f in lfs.dir(".") do
-    local mime = mg.get_mime_type(f)
-    mg.write("<li>" .. f .. " (" .. mime .. ")</li>\n")
-    local at = lfs.attributes(f);
-    recurse(at)
+    cnt = cnt + 1
+    if (cnt < 6) then
+      local mime = mg.get_mime_type(f)
+      mg.write("<li>" .. f .. " (" .. mime .. ")</li>\n")
+      local at = lfs.attributes(f);
+      recurse(at)
+    end
   end
   mg.write("</ul>\n")
+  mg.write(string.format("<ul>%u files total</ul>\n", cnt))
 end
 
 mg.write([[
 </p>
 </body></html>
 ]])
+

+ 3 - 3
test/page3.lua

@@ -7,14 +7,14 @@ if not mg.request_info.query_string then
     mg.write("Connection: close\r\n")
     mg.write("Content-Type: text/html; charset=utf-8\r\n")
     mg.write("\r\n")
-    mg.write("<html><head><title>Civetweb Lua script test page 3</title></head>\r\n")
+    mg.write("<html><head><title>CivetWeb Lua script test page 3</title></head>\r\n")
     mg.write("<body>No query string!</body></html>\r\n")
 elseif mg.request_info.query_string:match("/") or mg.request_info.query_string:match("\\") then
     mg.write("HTTP/1.0 403 Forbidden\r\n")
     mg.write("Connection: close\r\n")
     mg.write("Content-Type: text/html; charset=utf-8\r\n")
     mg.write("\r\n")
-    mg.write("<html><head><title>Civetweb Lua script test page 3</title></head>\r\n")
+    mg.write("<html><head><title>CivetWeb Lua script test page 3</title></head>\r\n")
     mg.write("<body>No access!</body></html>\r\n")
 else
     file = mg.get_var(mg.request_info.query_string, "file");
@@ -23,7 +23,7 @@ else
         mg.write("Connection: close\r\n")
         mg.write("Content-Type: text/html; charset=utf-8\r\n")
         mg.write("\r\n")
-        mg.write("<html>\r\n<head><title>Civetweb Lua script test page 3</title></head>\r\n")
+        mg.write("<html>\r\n<head><title>CivetWeb Lua script test page 3</title></head>\r\n")
         mg.write("<body>\r\nQuery string does not contain a 'file' variable.<br>\r\n")
         mg.write("Try <a href=\"?file=page3.lua&somevar=something\">?file=page3.lua&somevar=something</a>\r\n")
         mg.write("</body>\r\n</html>\r\n")

+ 3 - 3
test/page4.lua

@@ -2,7 +2,7 @@
 -- get_var, get_cookie, md5, url_encode
 
 now = os.time()
-cookie_name = "civetweb-test-page4"
+cookie_name = "CivetWeb-test-page4"
 
 if mg.request_info.http_headers.Cookie then
    cookie_value = tonumber(mg.get_cookie(mg.request_info.http_headers.Cookie, cookie_name))
@@ -17,8 +17,8 @@ if not cookie_value then
 end
 mg.write("\r\n")
 
-mg.write("<html>\r\n<head><title>Civetweb Lua script test page 4</title></head>\r\n<body>\r\n")
-mg.write("<p>Test of Civetweb Lua Functions:</p>\r\n");
+mg.write("<html>\r\n<head><title>CivetWeb Lua script test page 4</title></head>\r\n<body>\r\n")
+mg.write("<p>Test of CivetWeb Lua Functions:</p>\r\n");
 mg.write("<pre>\r\n");
 
 -- get_var of query_string