diff options
Diffstat (limited to 'docs/net')
| -rw-r--r-- | docs/net/listen.md | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/docs/net/listen.md b/docs/net/listen.md index 333f0f2..cc464b3 100644 --- a/docs/net/listen.md +++ b/docs/net/listen.md @@ -5,6 +5,26 @@ net.listen(function, 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
+if the 'server' upvalue needs to be accessible inside of the network threads, you will need to make the value global or redefine it. the upvalue itself (as a argument to the listen function) will simply not exist when the route functions are called, despite it looking like they would be.
+because the route functions (GET, POST, etc..) are just assigning functions to these paths, and not running them, they will just not see the server value.
+this also explains another weird behaviour where routes can read locals before they've been defined. (the upvalues of the functions are defined when the listen function is complete)
+
+```lua
+llby.net.listen(function(server)
+ _G.server = server
+
+ server:GET("/", function(res, req)
+ --first will always be null, second will be null without the second line
+ print(server, _G.server)
+
+ --will be valid despite being defined later
+ print(awa)
+ end)
+
+ local awa = 22
+end)
+```
+
|name|default value|extra info|
|--|--|--|
|mimetypes|/etc/mime.types|file used to auto assign content-type when using res:sendfile, nil to skip|
@@ -22,20 +42,14 @@ the server will send these codes for these reasons |414|request uri is longer than max_uri|
```lua
-llib.net.listen(function(server)
+llby.net.listen(function(server)
...
end, 80)
```
-```lua
-llib.net.listen(function(server)
- ...
-end, 80)
-```
+### server:close
-### server:close **
-
-closes server
+closes server, will not halt other already accepted requests
### server:GET/POST/...
@@ -132,6 +146,8 @@ res.header["test"] = "wowa" res:sendfile(filepath, options?)
+this can return an error if the file is not found or if the user does not have read permissions
+
res.header["Content-Type"] is set automatically (unless already set) depending on the file extention, using /etc/mime.types, or whatever option was supplied to listen (see listen options)
options table
@@ -170,6 +186,8 @@ these can, of course be used with wildcards however you want req:roll(bytes?)
+> this will be changed to be a stream internally, see common.md
+
when bytes is null it will read as much as possible (may not be the full request)
will update req according to how the bytes needed to be parsed, returns the number of bytes read (not necessarily parsed), 0 if there
|
