Skip to content

Commit

Permalink
Edit docs for POST processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Burkalev authored and Konstantin Burkalev committed Jun 21, 2014
1 parent 739bf7b commit b17b244
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Table of Contents
* [removeConnection](#removeconnectionregid)
* [receiveData](#receivedataregid-data)
* [getPendingData](#getpendingdataregid)
* [processPostData](#processpostdatasid-realm-data)
* [Copyright and License](#copyright-and-license)
* [See Also](#see-also)

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

Wiola supports JSON and msgpack serializers.

From v0.3.1 Wiola also supports lightweight POST event publishing. See processPostData method and post-handler.lua for details.

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

Usage example
Expand Down Expand Up @@ -74,7 +77,7 @@ lua_package_path '/usr/local/lualib/wiola/?.lua;/usr/local/lualib/lua-MessagePac
# Configure a vhost
server {
# example location
# example location for websocket WAMP connection
location /ws/ {
lua_socket_log_errors off;
lua_check_client_abort on;
Expand All @@ -85,6 +88,14 @@ server {
content_by_lua_file $document_root/lua/wiola/handler.lua;
}
# example location for a lightweight POST event publishing
location /wslight/ {
lua_socket_log_errors off;
lua_check_client_abort on;
content_by_lua_file $document_root/lua/wiola/post-handler.lua;
}
}
```

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

removeConnection(regId)
---------------
------------------------------------------

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

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

receiveData(regId, data)
---------------
------------------------------------------

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.

Expand All @@ -155,11 +166,10 @@ Parameters:

Returns: nothing


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

getPendingData(regId)
---------------------------
------------------------------------------

Checks the store for new data for client.

Expand All @@ -174,6 +184,25 @@ Returns:

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

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

processPostData(sid, realm, data)
------------------------------------------

Process lightweight POST data from client containing a publish message. This method is intended for fast publishing
an event, for example, in case when WAMP client is a browser application, which makes some changes on backend server,
so backend is a right place to notify other WAMP subscribers, but making a full WAMP connection is not optimal.

Parameters:

* **sid** - nginx session connection ID
* **realm** - WAMP Realm to operate in
* **data** - data, received through POST (JSON-encoded WAMP publish event)

Returns:

* **response data** (JSON encoded WAMP response message in case of error, or { result = true })
* **httpCode** HTTP status code (HTTP_OK/200 in case of success, HTTP_FORBIDDEN/403 in case of error)

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

Expand Down
5 changes: 2 additions & 3 deletions build/post-handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
--

local wampServer = require "wiola"
local realm = "hga"
local realm = "testRealm"

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

--local req = ngx.var.request_body
ngx.req.read_body()
local req = ngx.req.get_body_data()

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

ngx.status = httpCode
ngx.say(res)
ngx.say(res) -- returns response to client

-- to cause quit the whole request rather than the current phase handler
ngx.exit(ngx.HTTP_OK)
5 changes: 2 additions & 3 deletions src/wiola/post-handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
--

local wampServer = require "wiola"
local realm = "hga"
local realm = "testRealm"

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

--local req = ngx.var.request_body
ngx.req.read_body()
local req = ngx.req.get_body_data()

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

ngx.status = httpCode
ngx.say(res)
ngx.say(res) -- returns response to client

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

0 comments on commit b17b244

Please sign in to comment.