소스 검색

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

bel 11 년 전
부모
커밋
4a771e33ed
3개의 변경된 파일14개의 추가작업 그리고 1개의 파일을 삭제
  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, "include", lsp_include, conn);
     reg_function(L, "redirect", lsp_redirect, conn);
     reg_function(L, "redirect", lsp_redirect, conn);
     reg_string(L, "version", CIVETWEB_VERSION);
     reg_string(L, "version", CIVETWEB_VERSION);
+    reg_string(L, "document_root", conn->ctx->config[DOCUMENT_ROOT]);
 
 
     // Export request_info
     // Export request_info
     lua_pushstring(L, "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 pushCount = 0;
     var allErrorCount = 0;
     var allErrorCount = 0;
     var autoTest = false;
     var autoTest = false;
+    var testType = "cgi";
 
 
     function runTest(method, isAsync) {
     function runTest(method, isAsync) {
 
 
@@ -51,7 +52,7 @@
 
 
       $.ajax({
       $.ajax({
         async: isAsync,
         async: isAsync,
-        url: 'echo.cgi?id=' + id,
+        url: 'echo.' + testType + '?id=' + id,
         type: method,
         type: method,
         timeout: 2000,
         timeout: 2000,
         data: { 'id' : id ,
         data: { 'id' : id ,
@@ -118,6 +119,9 @@
           <td>
           <td>
             <input id="testButton5" type="button" onclick="autoTest=!autoTest; javascript:runAutoTest()" value="automatic test"></input>
             <input id="testButton5" type="button" onclick="autoTest=!autoTest; javascript:runAutoTest()" value="automatic test"></input>
           </td>        
           </td>        
+          <td>
+            <input id="testButton6" type="button" onclick="testType = (testType=='cgi') ? 'lp' : 'cgi'; this.value=testType" value='cgi'></input>
+          </td>        
         </tr>
         </tr>
         
         
         <tr>
         <tr>