comparison src/luan/modules/http/tools/Run.luan @ 1607:fa066aaa068c

nginx caching
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 30 Apr 2021 20:23:28 -0600
parents d9a5405a3102
children d6ec67fa4a61
comparison
equal deleted inserted replaced
1606:7c7f28c724e8 1607:fa066aaa068c
24 print(i,line) 24 print(i,line)
25 i = i + 1 25 i = i + 1
26 end 26 end
27 end 27 end
28 28
29 local function form() %> 29 local function form()
30 Http.response.headers["Content-Type"] = "text/html; charset=utf-8"
31 %>
30 <!doctype html> 32 <!doctype html>
31 <html> 33 <html>
32 <head> 34 <head>
33 <title>Run Luan Code</title> 35 <title>Run Luan Code</title>
34 <style> 36 <style>
52 </style> 54 </style>
53 </head> 55 </head>
54 <body> 56 <body>
55 <h2>Run Luan Code</h2> 57 <h2>Run Luan Code</h2>
56 <form method="post"> 58 <form method="post">
57 <input type="hidden" name="content_type" value="text/plain; charset=utf-8" />
58 <div> 59 <div>
59 <textarea name="code" rows="20" cols="90" autofocus></textarea> 60 <textarea name="code" rows="20" cols="90" autofocus></textarea>
60 </div> 61 </div>
61 <div> 62 <div>
62 <input type="submit" value="Execute Luan Code"/> 63 <input type="submit" value="Execute Luan Code"/>
63 </div> 64 </div>
64 </form> 65 </form>
65 </body> 66 </body>
66 </html> 67 </html>
67 <% end 68 <%
69 end
68 70
69 function Run.run(code,source_name) 71 function Run.run(code,source_name)
70 try 72 try
73 Http.response.headers["Content-Type"] = "text/plain; charset=utf-8"
71 local run = load(code,source_name) 74 local run = load(code,source_name)
72 run() 75 run()
73 return true 76 return true
74 catch e 77 catch e
75 Http.response.reset() 78 Http.response.reset()
76 Http.response.headers["content-type"] = "text/plain; charset=utf-8" 79 Http.response.headers["Content-Type"] = "text/plain; charset=utf-8"
77 Io.stdout = Http.response.text_writer() 80 Io.stdout = Http.response.text_writer()
78 print(e) 81 print(e)
79 print() 82 print()
80 print() 83 print()
81 print_with_line_numbers(code) 84 print_with_line_numbers(code)
82 return false 85 return false
83 end 86 end
84 end 87 end
85 88
86 function Run.respond() 89 function Run.respond()
87 local content_type = Http.request.parameters.content_type
88 if content_type ~= nil then
89 Http.response.headers["content-type"] = content_type
90 end
91 Io.stdout = Http.response.text_writer() 90 Io.stdout = Http.response.text_writer()
92 local code = Http.request.parameters.code 91 local code = Http.request.parameters.code
93 if code == nil then 92 if code == nil then
94 form() 93 form()
95 return 94 return