# net ## listen (mostly IMPLEMENTED) '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 ** right now everything within a server:GET function is partially global, it can read global variables (by making a copy), it can not read/copy local variables or modify globals ** allows a third optional argument that offers some other options in a table format |name|default value|extra info| |--|--|--| |mime.types.file**|/etc/mime.types|formated similarly to [this](https://wiki.debian.org/MIME/etc/mime.types)| |max.connections**|64|maximum number of connections that can be opened at the same time, will respond with error(503)| |max.header.size**|1<<20 (1048576)|max header size before refusing connection with error(431)| |max.uri.size**|idk yet|maximum uri size before refusing request with error(414)| |max.request.timeout**|idk yet|maximum time server will wait for request to be parsed| the server will send these codes for these reasons |code|cause| |--|--| |503**|too many current requests, more than max.connections| |500**|anytime a server route crashes| |431**|header is larger than max header size, more than max.header.size| |414**|request uri is longer than max.uri.size| |408**|request took too longer than max.request.timeout| |404**|request has no defined route| (more to come?**) ```lua llib.net.listen(function(server) ... end, 80) ``` ```lua llib.net.listen(function(server) ... end, 80, {["mime.types.file"] = "/etc/mime.types"}) ``` ### server:lock server:unlock continues on the current thread, but pauses all other threads at that point ```lua ... server:lock() --do something with a global server:unlock() ... ``` ### server:close ** closes server ### server:GET/POST/... 'takes a string (the path) and a function to be ran in the background on request 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 it also allows for path paramaters which is a wildcard directory that pushes the results into req.paramaters (read below) the actual name of the function will change based on what request method you want to accept, all requests are treated the exact same on the backend, besides HEAD requests which will also use all GET requets, and the 'all' variant will get everything ```lua server:all("*", function(res, req) if(req['Version'] ~= "HTTP/1.1") then res:stop() end end) ... server:GET("/", function(res, req) --version will always be 1.1, because the request passes through the function sequentially ... end) ... server:GET("/home/{user}/id", function(res, req) --sets req.paramaters.user to whatever path was requested end) ``` #### res:write '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:write("