Skip to content

Commit 90aa6d6

Browse files
committed
http/{request,websocket}: websocket :scheme is "http" not "ws"
RFC 8441 Section 5 says that the `:scheme` for websockets in HTTP/2 should be "http" or "https" rather than "ws" or "wss". It seems like this should apply to our HTTP/1.1 headers expressed in terms of HTTP/2 header structures.
1 parent 2dadd7d commit 90aa6d6

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

http/proxies.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ function proxies_methods:choose(scheme, host)
5757
end
5858
end
5959
end
60-
if scheme == "http" or scheme == "ws" then
60+
if scheme == "http" then
6161
if self.http_proxy then
6262
return self.http_proxy
6363
end
64-
elseif scheme == "https" or scheme == "wss" then
64+
elseif scheme == "https" then
6565
if self.https_proxy then
6666
return self.https_proxy
6767
end

http/request.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ local function new_from_uri(uri_t, headers)
7777
path = path .. "?" .. uri_t.query
7878
end
7979
headers:upsert(":path", path)
80+
if scheme == "wss" then
81+
scheme = "https"
82+
elseif scheme == "ws" then
83+
scheme = "http"
84+
end
8085
headers:upsert(":scheme", scheme)
8186
end
8287
if uri_t.userinfo then
@@ -95,7 +100,7 @@ local function new_from_uri(uri_t, headers)
95100
return setmetatable({
96101
host = host;
97102
port = port;
98-
tls = (scheme == "https" or scheme == "wss");
103+
tls = (scheme == "https");
99104
headers = headers;
100105
body = nil;
101106
}, request_mt)
@@ -209,9 +214,9 @@ function request_methods:handle_redirect(orig_headers)
209214
if not is_connect then
210215
new_req.headers:upsert(":scheme", new_scheme)
211216
end
212-
if new_scheme == "https" or new_scheme == "wss" then
217+
if new_scheme == "https" then
213218
new_req.tls = true
214-
elseif new_scheme == "http" or new_scheme == "ws" then
219+
elseif new_scheme == "http" then
215220
new_req.tls = false
216221
else
217222
return nil, "unknown scheme", ce.EINVAL

http/websocket.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,6 @@ end
545545

546546
local function new_from_uri(uri, protocols)
547547
local request = http_request.new_from_uri(uri)
548-
local scheme = request.headers:get(":scheme")
549-
assert(scheme == "ws" or scheme == "wss", "scheme not websocket")
550548
local self = new("client")
551549
self.request = request
552550
self.request.version = 1.1

spec/websocket_spec.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ describe("http.websocket module two sided tests", function()
375375
port = 0;
376376
onstream = function(s, stream)
377377
local headers = assert(stream:get_headers())
378+
assert.same("http", headers:get(":scheme"))
378379
local ws = websocket.new_from_stream(stream, headers)
379380
assert(ws:accept())
380381
assert(ws:close())

0 commit comments

Comments
 (0)