diff options
| author | ame <[email protected]> | 2024-08-03 02:30:02 -0500 |
|---|---|---|
| committer | ame <[email protected]> | 2024-08-03 02:30:02 -0500 |
| commit | 76ce905ef3e93f067b6d06458186bcf9eb9b5c01 (patch) | |
| tree | cbfee9fffc70d07bfd6b632e1f73b17da19d578c /tests/net2.lua | |
| parent | 2d9c55685ef75b8cf2cbc4eabd4b2875a354acba (diff) | |
fix tests, module based require, thread improvments
Diffstat (limited to 'tests/net2.lua')
| -rw-r--r-- | tests/net2.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/net2.lua b/tests/net2.lua new file mode 100644 index 0000000..0ef3644 --- /dev/null +++ b/tests/net2.lua @@ -0,0 +1,23 @@ +--(this is in tests/net2.lua) +net = require "lullaby.net" +crypto = require "lullaby.crypto" +local port = 8080 +MAX_LENGTH = 2048 + +net.listen(function(server) + + --listen to post requests at localhost:8080 (root directory) + server:POST("/", function(res, req) + --creates a sha0 hash object + local hash = crypto.sha0() + --loads an extra 2048 characters from the request body (the body is not guaranteed to be >= 2048 characters, reasoning in docs) + req:roll(MAX_LENGTH) + + --incremental hashes allow updating via addition, in this case adding the body and getting a string from it + hash = (hash + req.Body):final() + --send the hash to the client, closes connection, but thread is live until it ends + res:send(hash) + end) + +end, port) + |
