-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(proxy) supports websockets #1827
Merged
+57
−0
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if I understand correctly, this will set the headers to be sent to upstream as:
Connection: upgrade
by defaultConnection: close
if the downstreamUpgrade
header is not set.If so, this is a no-no. Switching to
HTTP/1.1
is a good change (which we should have done a while ago but somehow never did. Properly managing theConnection
header is also something that we somehow never implemented (very bad, proxies and gateways should never forward it to upstream services). But this is too rushed and not thought through.In
HTTP/1.1
, connections are considered persistent by default. This means that unless aConnection: close
header is sent from a client, the server will consider the connection as being persistent. Now, the problem here is that the defined behavior is to sendConnection: close
as soon as noUpgrade
header is received from downstream, which means: no persistent connections, ever.I believe a better solution could be:
To be tested of course.