Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moteus/lua-pegasus-websocket
WebSocket plugin for Pegasus http server
https://github.com/moteus/lua-pegasus-websocket
Last synced: 13 days ago
JSON representation
WebSocket plugin for Pegasus http server
- Host: GitHub
- URL: https://github.com/moteus/lua-pegasus-websocket
- Owner: moteus
- License: mit
- Created: 2017-11-08T10:26:46.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-09T07:42:11.000Z (about 7 years ago)
- Last Synced: 2024-10-26T12:49:35.120Z (18 days ago)
- Language: Lua
- Homepage:
- Size: 10.7 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-pegasus-websocket
WebSocket plugin for [Pegasus](http://evandrolg.github.io/pegasus.lua) http server### Limitations
This plugin just do upgrade and returns raw socket. So user have to use
some other library to handle actuall WebSocket protocol.### Usage
```Lua
local Pegasus = require "pegasus"
local WebSocket = require "pegasus.plugins.websocket"local server = Pegasus:new{ plugins = {
WebSocket:new{
protocols = { 'echo' }
}
} }server:start(function(request, response)
-- have to receive full request
request:receiveBody()if request:is_upgrade() then
local protocol, client = response:upgrade()
if client then
-- because we have only one plugin its can be only websocket
assert(protocol == 'websocket')
-- detect choosen sub protocol
protocol = response.headers['Sec-WebSocket-Protocol']
print("Upgrade to websocket:", protocol)
print(' - Socket:', client)
-- here we need wrap `client` to new WebSocket socket
....
return
end
print('Can not do upgrade')
endend)
```