Explorar el Código

Extend ajax test to use both, cgi (with Lua as standalone cgi interpreter) and lp (with Lua embedded in the server)

bel hace 11 años
padre
commit
4a771e33ed
Se han modificado 3 ficheros con 14 adiciones y 1 borrados
  1. 1 0
      src/mod_lua.inl
  2. 8 0
      test/ajax/echo.lp
  3. 5 1
      test/ajax/test.html

+ 1 - 0
src/mod_lua.inl

@@ -296,6 +296,7 @@ static void prepare_lua_environment(struct mg_connection *conn, lua_State *L)
     reg_function(L, "include", lsp_include, conn);
     reg_function(L, "redirect", lsp_redirect, conn);
     reg_string(L, "version", CIVETWEB_VERSION);
+    reg_string(L, "document_root", conn->ctx->config[DOCUMENT_ROOT]);
 
     // Export request_info
     lua_pushstring(L, "request_info");

+ 8 - 0
test/ajax/echo.lp

@@ -0,0 +1,8 @@
+<?
+function print(txt) mg.write(txt .. "\r\n") end
+mg.write("HTTP/1.1 200 OK\r\n")
+n = string.match(mg.request_info.uri, "^(.*)%.lp$")
+n = string.gsub(n, [[/]], [[\]])
+n = mg.document_root .. n .. ".cgi"
+dofile(n)
+?>

+ 5 - 1
test/ajax/test.html

@@ -17,6 +17,7 @@
     var pushCount = 0;
     var allErrorCount = 0;
     var autoTest = false;
+    var testType = "cgi";
 
     function runTest(method, isAsync) {
 
@@ -51,7 +52,7 @@
 
       $.ajax({
         async: isAsync,
-        url: 'echo.cgi?id=' + id,
+        url: 'echo.' + testType + '?id=' + id,
         type: method,
         timeout: 2000,
         data: { 'id' : id ,
@@ -118,6 +119,9 @@
           <td>
             <input id="testButton5" type="button" onclick="autoTest=!autoTest; javascript:runAutoTest()" value="automatic test"></input>
           </td>        
+          <td>
+            <input id="testButton6" type="button" onclick="testType = (testType=='cgi') ? 'lp' : 'cgi'; this.value=testType" value='cgi'></input>
+          </td>        
         </tr>
         
         <tr>