Skip to content

Commit 9a2579d

Browse files
HHHartmannmarcelstoer
authored andcommitted
Improve httpserver documentation (#2971)
1 parent e3935de commit 9a2579d

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

docs/lua-modules/httpserver.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,35 @@ Callback function has 2 arguments: `req` (request) and `res` (response). The fir
3636
object.
3737
- `method`: Request method that was used (e.g.`POST` or `GET`)
3838
- `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:
4041

4142
- `self`: `req` object
42-
- `name`: Header name
43+
- `name`: Header name. Will allways be lowercase.
4344
- `value`: Header value
4445

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:
4648
- `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
4850

4951
The second object holds functions:
5052

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.
5469

5570
Full example can be found in [http-example.lua](../../lua_modules/http/http-example.lua)

lua_modules/http/httpserver.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ do
116116
if not req or not req.ondata then return end
117117
req:ondata(chunk)
118118
-- NB: once length of seen chunks equals Content-Length:
119-
-- onend(conn) is called
119+
-- ondata(conn) is called
120120
body_len = body_len + #chunk
121121
-- print("-B", #chunk, body_len, cnt_len, node.heap())
122122
if body_len >= cnt_len then

0 commit comments

Comments
 (0)