aboutsummaryrefslogtreecommitdiff
path: root/tests/old/net2.lua
diff options
context:
space:
mode:
authoramelia squires <[email protected]>2025-04-16 13:09:46 -0500
committeramelia squires <[email protected]>2025-04-16 13:09:46 -0500
commit009eb7d43d9582856c275ad3b16f7e3ff94209cc (patch)
tree6d1f5ea000a6d72164a5b6e05b68dfbe0371ae06 /tests/old/net2.lua
parentdd7a8af4050454c3901987bff24a77334f892cc4 (diff)
merge thingy
Diffstat (limited to 'tests/old/net2.lua')
-rw-r--r--tests/old/net2.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/old/net2.lua b/tests/old/net2.lua
new file mode 100644
index 0000000..bb69051
--- /dev/null
+++ b/tests/old/net2.lua
@@ -0,0 +1,24 @@
+--(this is in tests/net2.lua)
+net = require "lullaby.net"
+local 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()
+ print(hash, crypto)
+ --send the hash to the client, closes connection, but thread is live until it ends
+ res:send(hash)
+ end)
+
+end, port)
+