-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: do not emit
upgrade
on advertisement
Do not emit `upgrade` if the server is just advertising its protocols support as per RFC 7230 Section 6.7. A server MAY send an Upgrade header field in any other response to advertise that it implements support for upgrading to the listed protocols, in order of descending preference, when appropriate for a future request. Fix: #4334 PR-URL: #4337 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
- Loading branch information
Showing
5 changed files
with
82 additions
and
1 deletion.
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
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,54 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const tests = [ | ||
{ headers: {}, expected: 'regular' }, | ||
{ headers: { upgrade: 'h2c' }, expected: 'regular' }, | ||
{ headers: { connection: 'upgrade' }, expected: 'regular' }, | ||
{ headers: { connection: 'upgrade', upgrade: 'h2c' }, expected: 'upgrade' } | ||
]; | ||
|
||
function fire() { | ||
if (tests.length === 0) | ||
return server.close(); | ||
|
||
const test = tests.shift(); | ||
|
||
const done = common.mustCall(function done(result) { | ||
assert.equal(result, test.expected); | ||
|
||
fire(); | ||
}); | ||
|
||
const req = http.request({ | ||
port: common.PORT, | ||
path: '/', | ||
headers: test.headers | ||
}, function onResponse(res) { | ||
res.resume(); | ||
done('regular'); | ||
}); | ||
|
||
req.on('upgrade', function onUpgrade(res, socket) { | ||
socket.destroy(); | ||
done('upgrade'); | ||
}); | ||
|
||
req.end(); | ||
} | ||
|
||
const server = http.createServer(function(req, res) { | ||
res.writeHead(200, { | ||
Connection: 'upgrade, keep-alive', | ||
Upgrade: 'h2c' | ||
}); | ||
res.end('hello world'); | ||
}).on('upgrade', function(req, socket) { | ||
socket.end('HTTP/1.1 101 Switching protocols\r\n' + | ||
'Connection: upgrade\r\n' + | ||
'Upgrade: h2c\r\n\r\n' + | ||
'ohai'); | ||
}).listen(common.PORT, fire); |
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