aboutsummaryrefslogtreecommitdiff
path: root/tests/net.lua
blob: fdb17d49e682e7bf33e4963988ace7772a5a711c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--yes, this is kinda a mess of requires, just proof it works:3
net = require "lullaby.net"
io = require "lullaby.io"
crypto = require "lullaby.crypto"
config = require "lullaby.config"

config.set({max_depth=5})

sleep = function(a) 
    local sec = tonumber(os.clock() + a); 
    while (os.clock() < sec) do 
    end 
end

net.listen(
    function(server)

        io.pprint("online")
        _G.server = server

        server:all("/{name}", function(res, req)
          print("name is "..req.name)
        end)
        server:all("*", function(res, req)
          print("all")
        end)

        server:all("/", function(res, req)
            b = crypto.md5("hello")

            res:send(b)
            
            a = req:roll()

            while a > -1 do 
                a = req:roll()
                print(req._bytes .. "/" .. req["Content-Length"])
            end
            io.pprint(req)

        end)

        server:GET("/aa", function(res, req)
            res.header["Content-Type"] = "text/plain"
            res:sendfile("readme.md")
        end)

        server:GET("/test55", function(res, req)
            res.Code = 403
            res:send("<h2>you would never</h2>")
        end)


        
    end,
    arg[1]
)