mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-19 16:13:07 +08:00
commit
a560334fbb
@ -307,8 +307,9 @@ like request method, all headers, etcetera. Please refer to
|
||||
`struct mg_request_info` definition in
|
||||
[mongoose.h](https://github.com/valenok/mongoose/blob/master/mongoose.h)
|
||||
to see what kind of information is present in `request_info` object. Also,
|
||||
[page.lp](https://github.com/valenok/mongoose/blob/master/test/page.lp)
|
||||
contains some example code that uses `request_info`.
|
||||
[page.lp](https://github.com/valenok/mongoose/blob/master/test/page.lp) and
|
||||
[prime_numbers.lp](https://github.com/valenok/mongoose/blob/master/examples/lua/prime_numbers.lp)
|
||||
contains some example code that uses `request_info` and other functions(form submitting for example).
|
||||
|
||||
|
||||
One substantial difference of mongoose's Lua Pages and PHP is that Mongoose
|
||||
|
42
examples/lua/prime_numbers.lp
Normal file
42
examples/lua/prime_numbers.lp
Normal file
@ -0,0 +1,42 @@
|
||||
<?
|
||||
-- Lua server pages have full control over the output, including HTTP
|
||||
-- headers they send to the client. Send HTTP headers:
|
||||
print('HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n')
|
||||
?>
|
||||
|
||||
<html>
|
||||
<p>Prime numbers from 0 to 100, calculated by Lua:</p>
|
||||
<?
|
||||
function is_prime(n)
|
||||
if n <= 0 then return false end
|
||||
if n <= 2 then return true end
|
||||
if (n % 2 == 0) then return false end
|
||||
for i = 3, n / 2, 2 do
|
||||
if (n % i == 0) then return false end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
for i = 1, 100 do
|
||||
if is_prime(i) then print('<span>' .. i .. '</span> ') end
|
||||
end
|
||||
|
||||
?>
|
||||
|
||||
<p>Reading POST data from Lua (click submit):</p>
|
||||
<form method="POST" ><input type="text" name="t1"/><input type="submit"></form>
|
||||
|
||||
<pre>
|
||||
POST data: [<? print(read())?>]
|
||||
request method: [<? print(request_info.request_method) ?>]
|
||||
IP/port: [<? print(request_info.remote_ip, ':', request_info.remote_port) ?>]
|
||||
URI: [<? print(request_info.uri) ?>]
|
||||
HTTP version [<? print(request_info.http_version) ?>]
|
||||
HEADERS:
|
||||
<?
|
||||
for name, value in pairs(request_info.http_headers) do
|
||||
print(name, ':', value, '\n')
|
||||
end
|
||||
?>
|
||||
</pre>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user