Add node modules and compiled JavaScript from main (#54)
Co-authored-by: Oliver King <oking3@uncc.edu>
This commit is contained in:
committed by
GitHub
parent
4a983766a0
commit
52d71d28bd
22
node_modules/resolve-alpn/LICENSE
generated
vendored
Normal file
22
node_modules/resolve-alpn/LICENSE
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Szymon Marczak
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
60
node_modules/resolve-alpn/README.md
generated
vendored
Normal file
60
node_modules/resolve-alpn/README.md
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
# `resolve-alpn`
|
||||
|
||||
[](https://github.com/szmarczak/resolve-alpn/actions)
|
||||
[](https://codecov.io/gh/szmarczak/resolve-alpn)
|
||||
|
||||
## API
|
||||
|
||||
### resolveALPN(options, connect = tls.connect)
|
||||
|
||||
Returns an object with an `alpnProtocol` property. The `socket` property may be also present.
|
||||
|
||||
```js
|
||||
const result = await resolveALPN({
|
||||
host: 'nghttp2.org',
|
||||
port: 443,
|
||||
ALPNProtocols: ['h2', 'http/1.1'],
|
||||
servername: 'nghttp2.org'
|
||||
});
|
||||
|
||||
console.log(result); // {alpnProtocol: 'h2'}
|
||||
```
|
||||
|
||||
**Note:** While the `servername` option is not required in this case, many other servers do. It's best practice to set it anyway.
|
||||
|
||||
**Note:** If the socket times out, the promise will resolve and `result.timeout` will be set to `true`.
|
||||
|
||||
#### options
|
||||
|
||||
Same as [TLS options](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback).
|
||||
|
||||
##### options.resolveSocket
|
||||
|
||||
By default, the socket gets destroyed and the promise resolves.<br>
|
||||
If you set this to true, it will return the socket in a `socket` property.
|
||||
|
||||
```js
|
||||
const result = await resolveALPN({
|
||||
host: 'nghttp2.org',
|
||||
port: 443,
|
||||
ALPNProtocols: ['h2', 'http/1.1'],
|
||||
servername: 'nghttp2.org',
|
||||
resolveSocket: true
|
||||
});
|
||||
|
||||
console.log(result); // {alpnProtocol: 'h2', socket: tls.TLSSocket}
|
||||
|
||||
// Remember to destroy the socket if you don't use it!
|
||||
result.socket.destroy();
|
||||
```
|
||||
|
||||
#### connect
|
||||
|
||||
Type: `Function<TLSSocket> | AsyncFunction<TLSSocket>`\
|
||||
Default: [`tls.connect`](https://nodejs.org/dist/latest-v16.x/docs/api/tls.html#tls_tls_connect_options_callback)
|
||||
|
||||
**Note:** No matter which function is used (synchronous or asynchronous), it **must** accept a `callback` function as a second argument. The `callback` function gets executed when the socket has successfully connected.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
43
node_modules/resolve-alpn/index.js
generated
vendored
Normal file
43
node_modules/resolve-alpn/index.js
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
const tls = require('tls');
|
||||
|
||||
module.exports = (options = {}, connect = tls.connect) => new Promise((resolve, reject) => {
|
||||
let timeout = false;
|
||||
|
||||
let socket;
|
||||
|
||||
const callback = async () => {
|
||||
await socketPromise;
|
||||
|
||||
socket.off('timeout', onTimeout);
|
||||
socket.off('error', reject);
|
||||
|
||||
if (options.resolveSocket) {
|
||||
resolve({alpnProtocol: socket.alpnProtocol, socket, timeout});
|
||||
|
||||
if (timeout) {
|
||||
await Promise.resolve();
|
||||
socket.emit('timeout');
|
||||
}
|
||||
} else {
|
||||
socket.destroy();
|
||||
resolve({alpnProtocol: socket.alpnProtocol, timeout});
|
||||
}
|
||||
};
|
||||
|
||||
const onTimeout = async () => {
|
||||
timeout = true;
|
||||
callback();
|
||||
};
|
||||
|
||||
const socketPromise = (async () => {
|
||||
try {
|
||||
socket = await connect(options, callback);
|
||||
|
||||
socket.on('error', reject);
|
||||
socket.once('timeout', onTimeout);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
})();
|
||||
});
|
34
node_modules/resolve-alpn/package.json
generated
vendored
Normal file
34
node_modules/resolve-alpn/package.json
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "resolve-alpn",
|
||||
"version": "1.2.1",
|
||||
"description": "Detects the ALPN protocol",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "xo && nyc --reporter=lcovonly --reporter=text --reporter=html ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/szmarczak/resolve-alpn.git"
|
||||
},
|
||||
"keywords": [
|
||||
"alpn",
|
||||
"tls",
|
||||
"socket",
|
||||
"http2"
|
||||
],
|
||||
"author": "Szymon Marczak",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/szmarczak/resolve-alpn/issues"
|
||||
},
|
||||
"homepage": "https://github.com/szmarczak/resolve-alpn#readme",
|
||||
"devDependencies": {
|
||||
"ava": "^3.15.0",
|
||||
"nyc": "^15.1.0",
|
||||
"pem": "1.14.3",
|
||||
"xo": "^0.38.2"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user