test.lua revision c381599e85eb318a270f3e3b07851bff77e5c151
842ae4bd224140319ae7feec1872b93dfd491143fielding-- Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding-- contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding-- this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding-- The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding-- (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding-- the License. You may obtain a copy of the License at
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes--
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes-- http://www.apache.org/licenses/LICENSE-2.0
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes--
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes-- Unless required by applicable law or agreed to in writing, software
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes-- distributed under the License is distributed on an "AS IS" BASIS,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes-- See the License for the specific language governing permissions and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes-- limitations under the License.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesrequire 'string'
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesfunction print_args(r, simple, complex)
e8f95a682820a599fe41b22977010636be5c2717jim local s = " %s: %s\n"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts(" simple:\n")
e8f95a682820a599fe41b22977010636be5c2717jim for k, v in pairs(simple) do
1747d30b98aa1bdbc43994c02cd46ab4cb9319e4fielding r:puts(s:format(k, v))
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes end
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes s = " %s: "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts(" complex:\n")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for k, ary in pairs(complex) do
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts(s:format(k))
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for i=1, #ary do
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts(ary[i])
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if i < #ary then r:puts(", ") end
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes end
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts("\n")
5c0419d51818eb02045cf923a9fe456127a44c60wrowe end
5c0419d51818eb02045cf923a9fe456127a44c60wroweend
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesfunction debug_stuff(r)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:debug("This is a debug log message")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes -- r:info("This is an info log message")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes -- r:notice("This is an notice log message")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes -- r:warn("This is an warn log message")
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton -- r:err("This is an err log message")
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton -- r:alert("This is an alert log message")
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton -- r:crit("This is an crit log message")
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton -- r:emerg("This is an emerg log message")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesend
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholesfunction handle(r)
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes r:puts("hello Lua world\n")
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes r:puts("Query args:\n")
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes print_args(r, r:parseargs());
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes debug_stuff(r)
cd3bbd6d2df78d6c75e5d159a81ef8bdd5f70df9trawick
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts("HTTP Method:\n " .. r.method .. "\n")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if r.method == 'POST' then
0568280364eb026393be492ebc732795c4934643jorton print_args(r, r:parsebody())
0568280364eb026393be492ebc732795c4934643jorton end
0568280364eb026393be492ebc732795c4934643jorton
0568280364eb026393be492ebc732795c4934643jorton require("other")
0568280364eb026393be492ebc732795c4934643jorton r:puts("loaded relative to script:\n ")
0568280364eb026393be492ebc732795c4934643jorton other.doit(r)
0568280364eb026393be492ebc732795c4934643jorton
0568280364eb026393be492ebc732795c4934643jorton r:puts("loaded from LuaPackagePath:\n")
0568280364eb026393be492ebc732795c4934643jorton require("kangaroo");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes kangaroo.hop(r);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesend
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesfunction handle_foo(r)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts("Handler FOO!\n")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r.status = 201
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:debug("set status to 201")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesend
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
796e4a7141265d8ed7036e4628161c6eafb2a789jorton
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesfunction handle_attributes(r)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes local function pf(name)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts(("%s: %s\n"):format(name, tostring(r[name])))
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes end
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("status")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r.status = 201
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("status")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts("\n")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("content_type")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r.content_type = "text/plain?charset=ascii"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("content_type")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts("\n")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe pf("method")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("protocol")
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe pf("assbackwards")
e8f95a682820a599fe41b22977010636be5c2717jim pf("the_request")
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe pf("range")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("content_encoding")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("user")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("unparsed_uri")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("ap_auth_type")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("uri")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("filename")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("canonical_filename")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("path_info")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pf("args")
713a2b68bac4aeb1e9c48785006c0732451039depquerna
713a2b68bac4aeb1e9c48785006c0732451039depquerna r:puts("\n")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesend
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesfunction test_headers(r)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts("test getting and setting headers here\n")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesend
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowefunction handle_quietly(r)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts("hello!")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesend
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesfunction handle_regex(r)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts("matched in handle_regex")
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesend
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesfunction handle_serverversion(r)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts(apache2.version)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesend
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholesfunction handle_fixupstest(r)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r:puts("status is " .. r.status)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesend