-
Notifications
You must be signed in to change notification settings - Fork 559
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: more informative error message to tell that the server doesn't m…
…atch http/1.1 protocol (#2055) * fix: http2 error message * test: fix * test: fix
- Loading branch information
Showing
3 changed files
with
39 additions
and
5 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,32 @@ | ||
'use strict' | ||
|
||
const { test } = require('tap') | ||
const { Client, errors } = require('..') | ||
const { createSecureServer } = require('http2') | ||
const pem = require('https-pem') | ||
|
||
test('throw http2 not supported error', (t) => { | ||
t.plan(1) | ||
|
||
const server = createSecureServer({ key: pem.key, cert: pem.cert }, (req, res) => { | ||
res.stream.respond({ 'content-type': 'text/plain' }) | ||
res.stream.end('hello') | ||
}).on('unknownProtocol', (socket) => { | ||
// continue sending data in http2 to our http1.1 client to trigger error | ||
socket.write('PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n') | ||
}) | ||
t.teardown(server.close.bind(server)) | ||
|
||
server.listen(0, () => { | ||
const client = new Client(`https://localhost:${server.address().port}`, { | ||
tls: { | ||
rejectUnauthorized: false | ||
} | ||
}) | ||
t.teardown(client.close.bind(client)) | ||
|
||
client.request({ path: '/', method: 'GET' }, (err, data) => { | ||
t.type(err, errors.HTTPParserError) | ||
}) | ||
}) | ||
}) |
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