Skip to content

Commit b17b244

Browse files
Konstantin BurkalevKonstantin Burkalev
authored andcommitted
Edit docs for POST processing
1 parent 739bf7b commit b17b244

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

README.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Table of Contents
1717
* [removeConnection](#removeconnectionregid)
1818
* [receiveData](#receivedataregid-data)
1919
* [getPendingData](#getpendingdataregid)
20+
* [processPostData](#processpostdatasid-realm-data)
2021
* [Copyright and License](#copyright-and-license)
2122
* [See Also](#see-also)
2223

@@ -40,6 +41,8 @@ wiola supports next WAMP roles and features:
4041

4142
Wiola supports JSON and msgpack serializers.
4243

44+
From v0.3.1 Wiola also supports lightweight POST event publishing. See processPostData method and post-handler.lua for details.
45+
4346
[Back to TOC](#table-of-contents)
4447

4548
Usage example
@@ -74,7 +77,7 @@ lua_package_path '/usr/local/lualib/wiola/?.lua;/usr/local/lualib/lua-MessagePac
7477
7578
# Configure a vhost
7679
server {
77-
# example location
80+
# example location for websocket WAMP connection
7881
location /ws/ {
7982
lua_socket_log_errors off;
8083
lua_check_client_abort on;
@@ -85,6 +88,14 @@ server {
8588
content_by_lua_file $document_root/lua/wiola/handler.lua;
8689
}
8790
91+
# example location for a lightweight POST event publishing
92+
location /wslight/ {
93+
lua_socket_log_errors off;
94+
lua_check_client_abort on;
95+
96+
content_by_lua_file $document_root/lua/wiola/post-handler.lua;
97+
}
98+
8899
}
89100
```
90101

@@ -131,7 +142,7 @@ Returns:
131142
[Back to TOC](#table-of-contents)
132143

133144
removeConnection(regId)
134-
---------------
145+
------------------------------------------
135146

136147
Removes connection from viola control. Cleans all cached data. Do not neglect this method on connection termination.
137148

@@ -144,7 +155,7 @@ Returns: nothing
144155
[Back to TOC](#table-of-contents)
145156

146157
receiveData(regId, data)
147-
---------------
158+
------------------------------------------
148159

149160
This method should be called, when new data is received from web socket. This method analyze all incoming messages, set states and prepare response data for clients.
150161

@@ -155,11 +166,10 @@ Parameters:
155166

156167
Returns: nothing
157168

158-
159169
[Back to TOC](#table-of-contents)
160170

161171
getPendingData(regId)
162-
---------------------------
172+
------------------------------------------
163173

164174
Checks the store for new data for client.
165175

@@ -174,6 +184,25 @@ Returns:
174184

175185
This method is actualy a proxy for redis:lpop() method.
176186

187+
[Back to TOC](#table-of-contents)
188+
189+
processPostData(sid, realm, data)
190+
------------------------------------------
191+
192+
Process lightweight POST data from client containing a publish message. This method is intended for fast publishing
193+
an event, for example, in case when WAMP client is a browser application, which makes some changes on backend server,
194+
so backend is a right place to notify other WAMP subscribers, but making a full WAMP connection is not optimal.
195+
196+
Parameters:
197+
198+
* **sid** - nginx session connection ID
199+
* **realm** - WAMP Realm to operate in
200+
* **data** - data, received through POST (JSON-encoded WAMP publish event)
201+
202+
Returns:
203+
204+
* **response data** (JSON encoded WAMP response message in case of error, or { result = true })
205+
* **httpCode** HTTP status code (HTTP_OK/200 in case of success, HTTP_FORBIDDEN/403 in case of error)
177206

178207
[Back to TOC](#table-of-contents)
179208

build/post-handler.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
--
66

77
local wampServer = require "wiola"
8-
local realm = "hga"
8+
local realm = "testRealm"
99

1010
local redisOk, redisErr = wampServer.setupRedis("unix:/tmp/redis.sock")
1111
if not redisOk then
1212
return ngx.exit(444)
1313
end
1414

15-
--local req = ngx.var.request_body
1615
ngx.req.read_body()
1716
local req = ngx.req.get_body_data()
1817

1918
local res, httpCode = wampServer.processPostData(ngx.var.connection, realm, req)
2019

2120
ngx.status = httpCode
22-
ngx.say(res)
21+
ngx.say(res) -- returns response to client
2322

2423
-- to cause quit the whole request rather than the current phase handler
2524
ngx.exit(ngx.HTTP_OK)

src/wiola/post-handler.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@
55
--
66

77
local wampServer = require "wiola"
8-
local realm = "hga"
8+
local realm = "testRealm"
99

1010
local redisOk, redisErr = wampServer.setupRedis("unix:/tmp/redis.sock")
1111
if not redisOk then
1212
ngx.log(ngx.DEBUG, "Failed to connect to redis: ", redisErr)
1313
return ngx.exit(444)
1414
end
1515

16-
--local req = ngx.var.request_body
1716
ngx.req.read_body()
1817
local req = ngx.req.get_body_data()
1918

2019
local res, httpCode = wampServer.processPostData(ngx.var.connection, realm, req)
2120

2221
ngx.status = httpCode
23-
ngx.say(res)
22+
ngx.say(res) -- returns response to client
2423

2524
-- to cause quit the whole request rather than the current phase handler
2625
ngx.exit(ngx.HTTP_OK)

0 commit comments

Comments
 (0)