-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1827 from Mashape/feat/websockets
feat(proxy) supports websockets
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
local client = require "resty.websocket.client" | ||
local helpers = require "spec.helpers" | ||
local cjson = require "cjson" | ||
|
||
describe("Websockets", function() | ||
setup(function() | ||
assert(helpers.start_kong()) | ||
|
||
assert(helpers.dao.apis:insert { | ||
request_path = "/ws", | ||
strip_request_path = true, | ||
upstream_url = "http://sockb.in" | ||
}) | ||
end) | ||
|
||
teardown(function() | ||
helpers.stop_kong() | ||
end) | ||
|
||
local function make_request(uri) | ||
local wb = assert(client:new()) | ||
assert(wb:connect(uri)) | ||
assert(wb:send_text("testing Kong")) | ||
|
||
local data = assert(wb:recv_frame()) | ||
assert.equal("testing Kong", cjson.decode(data).reqData) | ||
|
||
assert(wb:send_close()) | ||
|
||
return true | ||
end | ||
|
||
it("works without Kong", function() | ||
assert(make_request("ws://sockb.in")) | ||
end) | ||
|
||
it("works with Kong", function() | ||
assert(make_request("ws://"..helpers.test_conf.proxy_ip..":"..helpers.test_conf.proxy_port.."/ws")) | ||
end) | ||
|
||
it("works with Kong under HTTPS", function() | ||
assert(make_request("wss://"..helpers.test_conf.proxy_ssl_ip..":"..helpers.test_conf.proxy_ssl_port.."/ws")) | ||
end) | ||
end) |