Rename http server Lua module and fix its documentation (#2594)
This commit is contained in:
parent
f5fcd0d984
commit
ebdfd1ff6a
|
@ -1,4 +1,4 @@
|
||||||
# HTTP Module
|
# HTTP Server Module
|
||||||
| Since | Origin / Contributor | Maintainer | Source |
|
| Since | Origin / Contributor | Maintainer | Source |
|
||||||
| :----- | :-------------------- | :---------- | :------ |
|
| :----- | :-------------------- | :---------- | :------ |
|
||||||
| 2015-01-19 | [Vladimir Dronnikov](https://github.com/dvv) | [Vladimir Dronnikov](https://github.com/dvv) | [http.lua](../../../lua_modules/http/http.lua) |
|
| 2015-01-19 | [Vladimir Dronnikov](https://github.com/dvv) | [Vladimir Dronnikov](https://github.com/dvv) | [http.lua](../../../lua_modules/http/http.lua) |
|
||||||
|
@ -7,17 +7,17 @@ This Lua module provides a simple callback implementation of a [HTTP 1.1](https:
|
||||||
|
|
||||||
### Require
|
### Require
|
||||||
```lua
|
```lua
|
||||||
httpserver = require("http")
|
httpserver = require("httpserver")
|
||||||
```
|
```
|
||||||
|
|
||||||
### Release
|
### Release
|
||||||
```lua
|
```lua
|
||||||
httpserver = nil
|
httpserver = nil
|
||||||
package.loaded["http"] = nil
|
package.loaded["httpserver"] = nil
|
||||||
```
|
```
|
||||||
|
|
||||||
## httpserver.createServer()
|
## httpserver.createServer()
|
||||||
Function to start HTTP 1.1 server.
|
Function to start HTTP server.
|
||||||
|
|
||||||
#### Syntax
|
#### Syntax
|
||||||
`httpserver.createServer(port, handler(req, res))`
|
`httpserver.createServer(port, handler(req, res))`
|
||||||
|
@ -30,17 +30,25 @@ Function to start HTTP 1.1 server.
|
||||||
`net.server` sub module.
|
`net.server` sub module.
|
||||||
|
|
||||||
#### Notes
|
#### Notes
|
||||||
Callback function has 2 arguments : `req` (request) and `res` (response). The first object holds values:
|
Callback function has 2 arguments: `req` (request) and `res` (response). The first object holds values:
|
||||||
|
|
||||||
- `conn`: net.server sub module
|
- `conn`: `net.server` sub module
|
||||||
- `method`: Request method like `POST` or `GET`
|
- `method`: Request method that was used (e.g.`POST` or `GET`)
|
||||||
- `url`: Request URL
|
- `url`: Requested URL
|
||||||
- `onheader`: value to setup handler function for HTTP headers
|
- `onheader`: value to setup handler function for HTTP headers like `content-type`. Handler function has 3 parameters:
|
||||||
- `ondata`: value to setup handler function HTTP data like `content-type`
|
|
||||||
|
- `self`: `req` object
|
||||||
|
- `name`: Hearder name
|
||||||
|
- `value`: Header value
|
||||||
|
|
||||||
|
- `ondata`: value to setup handler function HTTP data. Handler function has 2 parameters:
|
||||||
|
- `self`: `req` object
|
||||||
|
- `chunk`: Request data
|
||||||
|
|
||||||
The second object holds functions:
|
The second object holds functions:
|
||||||
- `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)
|
|
||||||
- `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.
|
- `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)
|
||||||
|
- `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.
|
||||||
- `finish([data])`: Function to finalize connection, optionally sending data. `data` is optional data to send on connection finalizing.
|
- `finish([data])`: Function to finalize connection, optionally sending data. `data` is optional data to send on connection finalizing.
|
||||||
|
|
||||||
Full example can be found in [http-example.lua](../../../lua_modules/http/http-example.lua)
|
Full example can be found in [http-example.lua](../../../lua_modules/http/http-example.lua)
|
|
@ -4,7 +4,7 @@
|
||||||
-- LICENCE: http://opensource.org/licenses/MIT
|
-- LICENCE: http://opensource.org/licenses/MIT
|
||||||
-- Vladimir Dronnikov <dronnikov@gmail.com>
|
-- Vladimir Dronnikov <dronnikov@gmail.com>
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
require("http").createServer(80, function(req, res)
|
require("httpserver").createServer(80, function(req, res)
|
||||||
-- analyse method and url
|
-- analyse method and url
|
||||||
print("+R", req.method, req.url, node.heap())
|
print("+R", req.method, req.url, node.heap())
|
||||||
-- setup handler of headers, if any
|
-- setup handler of headers, if any
|
||||||
|
|
|
@ -43,6 +43,7 @@ pages:
|
||||||
- 'ds3231': 'en/lua-modules/ds3231.md'
|
- 'ds3231': 'en/lua-modules/ds3231.md'
|
||||||
- 'ftpserver': 'en/lua-modules/ftpserver.md'
|
- 'ftpserver': 'en/lua-modules/ftpserver.md'
|
||||||
- 'hdc1000': 'en/lua-modules/hdc1000.md'
|
- 'hdc1000': 'en/lua-modules/hdc1000.md'
|
||||||
|
- 'httpserver': 'en/lua-modules/httpserver.md'
|
||||||
- 'imap': 'en/lua-modules/imap.md'
|
- 'imap': 'en/lua-modules/imap.md'
|
||||||
- 'lm92': 'en/lua-modules/lm92.md'
|
- 'lm92': 'en/lua-modules/lm92.md'
|
||||||
- 'mcp23008': 'en/lua-modules/mcp23008.md'
|
- 'mcp23008': 'en/lua-modules/mcp23008.md'
|
||||||
|
|
Loading…
Reference in New Issue