From 80f4057a7634fd51832f60ca5a91887d9cb853f2 Mon Sep 17 00:00:00 2001 From: ame Date: Mon, 5 Feb 2024 10:03:10 -0600 Subject: docs and functionality probably --- docs/net.md | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'docs/net.md') diff --git a/docs/net.md b/docs/net.md index b75ae46..b129aa1 100644 --- a/docs/net.md +++ b/docs/net.md @@ -4,6 +4,7 @@ 'takes a function with 1 argument and a integer for a port +(intentionally styled after expressjs:3) the function will be ran on initilization, the argument has info on the server and functions to set it up ** @@ -34,46 +35,51 @@ server:unlock() closes server -### server:use +### server:GET -'takes a function with 3 paramaters +'takes a string (the path) and a function to be ran in the background on request -first and second are res and req as described in server:GET, the third is a function to move to the next point, executes in the order given and can be chained +the function has 2 arguments, the first (res) contains functions and info about resolving the request, +the second (req) contains info on the request, the path allows for wildcards, multiple get requests per path is allowed ```lua -server:use(function(res, req, next) - if(req['Version'] == "HTTP/1.1") then - next() + + +server:GET("*", function(res, req, next) + if(req['Version'] ~= "HTTP/1.1") then + res:deny() end end) -server:GET("/", function(res, req) +... +server:GET("/", function(res, req) do --version will always be 1.1, as per the middleware + ... end) +... ``` -### server:GET - -'takes a string (the path) and a function to be ran in the background on request +#### res:deny ** -the function has 2 arguments, the first (res) contains functions and info about resolving the request, -the second (req) contains info on the request +denies request as if there was no server ```lua ... -server:GET("/", function(res, req) do - ... -end) +res:deny() --make the client timeout, lol ... ``` -#### res:deny ** +#### res:write -denies request as if there was no server +'takes a string + +sends the string to the client, constructs a header on first call (whether or not res.header._sent is null) +(the constructed header can not be changed later on in the request), and sends the string without closing the client ```lua ... -res:deny() --make the client timeout, lol +res:write("

hello world

") +res:write("

good bye world

") ... ``` @@ -81,7 +87,7 @@ res:deny() --make the client timeout, lol 'takes a string -sends the string to the client +sends the string to the client, constructs a header then closes client_fd ```lua ... @@ -89,9 +95,9 @@ res:send("

hello world

") ... ``` -#### res:close ** +#### res:end -closes connection +closes connection, sets res.client_fd to -1, any calls that use this value will fail #### res.header -- cgit v1.2.3