You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/lua-modules/httpserver.md
+22-7Lines changed: 22 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,20 +36,35 @@ Callback function has 2 arguments: `req` (request) and `res` (response). The fir
36
36
object.
37
37
-`method`: Request method that was used (e.g.`POST` or `GET`)
38
38
-`url`: Requested URL
39
-
-`onheader`: value to setup handler function for HTTP headers like `content-type`. Handler function has 3 parameters:
39
+
-`onheader`: assign a function to this value which will be called as soon as HTTP headers like `content-type` are available.
40
+
This handler function has 3 parameters:
40
41
41
42
- `self`: `req` object
42
-
- `name`: Header name
43
+
- `name`: Header name. Will allways be lowercase.
43
44
- `value`: Header value
44
45
45
-
-`ondata`: value to setup handler function HTTP data. Handler function has 2 parameters:
46
+
-`ondata`: assign a function to this value which will be called as soon as body data is available.
47
+
This handler function has 2 parameters:
46
48
- `self`: `req` object
47
-
- `chunk`: Request data
49
+
- `chunk`: Request data. If all data is received there will be one last call with data = nil
48
50
49
51
The second object holds functions:
50
52
51
-
-`send(self, data, [response_code])`: Function to send data to client. `self` is `req` object, `data` is data to send and `response_code` is HTTP response code like `200` or `404` (for example)
52
-
-`send_header(self, header_name, header_data)`: Function to send HTTP headers to client. `self` is `req` object, `header_name` is HTTP header name and `header_data` is HTTP header data for client.
53
-
-`finish([data])`: Function to finalize connection, optionally sending data. `data` is optional data to send on connection finalizing.
53
+
-`send(self, data, [response_code])`: Function to send data to client.
54
+
55
+
-`self`: `res` object
56
+
-`data`: data to send (may be nil)
57
+
-`response_code`: the HTTP response code like `200`(default) or `404` (for example) *NOTE* if there are several calls with response_code given only the first one will be used. Any further codes given will be ignored.
58
+
59
+
-`send_header(self, header_name, header_data)`: Function to send HTTP headers to client. This function will not be available after data has been sent. (It will be nil.)
60
+
61
+
-`self`: `res` object
62
+
-`header_name`: the HTTP header name
63
+
-`header_data`: the HTTP header data
64
+
65
+
-`finish([data[, response_code]])`: Function to finalize connection, optionally sending data and return code.
66
+
67
+
-`data`: optional data to send on connection finalizing
68
+
-`response_code`: the HTTP response code like `200`(default) or `404` (for example) *NOTE* if there are several calls with response_code given only the first one will be used. Any further codes given will be ignored.
54
69
55
70
Full example can be found in [http-example.lua](../../lua_modules/http/http-example.lua)
0 commit comments