mirror of
https://github.com/avwo/whistle.git
synced 2026-10-27 04:19:59 +08:00
refactor: refine code
This commit is contained in:
+10
-10
@@ -193,13 +193,13 @@ function createSelfCert(hostname) {
|
||||
altNames: [
|
||||
net.isIP(hostname)
|
||||
? {
|
||||
type: 7,
|
||||
ip: hostname
|
||||
}
|
||||
type: 7,
|
||||
ip: hostname
|
||||
}
|
||||
: {
|
||||
type: 2,
|
||||
value: hostname
|
||||
}
|
||||
type: 2,
|
||||
value: hostname
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
@@ -508,10 +508,10 @@ function getOrCreateCert(servername) {
|
||||
}
|
||||
return requestCert
|
||||
? extend(
|
||||
{
|
||||
requestCert: true,
|
||||
rejectUnauthorized: false
|
||||
},
|
||||
{
|
||||
requestCert: true,
|
||||
rejectUnauthorized: false
|
||||
},
|
||||
cert
|
||||
)
|
||||
: cert;
|
||||
|
||||
+12
-12
@@ -177,19 +177,19 @@ function getSocket(options, callback, isHttp) {
|
||||
: util.connect(
|
||||
isHttp
|
||||
? {
|
||||
host: options.host,
|
||||
port: options.port || 80
|
||||
}
|
||||
host: options.host,
|
||||
port: options.port || 80
|
||||
}
|
||||
: addCert(
|
||||
{
|
||||
servername: options.servername,
|
||||
host: options.host,
|
||||
port: options.port || 443,
|
||||
rejectUnauthorized: config.rejectUnauthorized,
|
||||
ALPNProtocols: SUPPORTED_PROTOS,
|
||||
NPNProtocols: SUPPORTED_PROTOS,
|
||||
_rules: options._rules
|
||||
},
|
||||
{
|
||||
servername: options.servername,
|
||||
host: options.host,
|
||||
port: options.port || 443,
|
||||
rejectUnauthorized: config.rejectUnauthorized,
|
||||
ALPNProtocols: SUPPORTED_PROTOS,
|
||||
NPNProtocols: SUPPORTED_PROTOS,
|
||||
_rules: options._rules
|
||||
},
|
||||
options
|
||||
),
|
||||
handleCallback
|
||||
|
||||
+22
-22
@@ -447,15 +447,15 @@ function resolveWebsocket(socket, wss) {
|
||||
'error',
|
||||
isXProxy
|
||||
? function () {
|
||||
if (isXProxy) {
|
||||
isXProxy = false;
|
||||
resData.phost = undefined;
|
||||
if (isInternalProxy) {
|
||||
options.protocol = origProto;
|
||||
}
|
||||
connectServer();
|
||||
if (isXProxy) {
|
||||
isXProxy = false;
|
||||
resData.phost = undefined;
|
||||
if (isInternalProxy) {
|
||||
options.protocol = origProto;
|
||||
}
|
||||
connectServer();
|
||||
}
|
||||
}
|
||||
: execCallback
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -897,18 +897,18 @@ function getStatusMessage(obj) {
|
||||
|
||||
function isIllegalcHeader(name, value) {
|
||||
switch (name) {
|
||||
case h2Consts.HTTP2_HEADER_CONNECTION:
|
||||
case h2Consts.HTTP2_HEADER_UPGRADE:
|
||||
case h2Consts.HTTP2_HEADER_HOST:
|
||||
case h2Consts.HTTP2_HEADER_HTTP2_SETTINGS:
|
||||
case h2Consts.HTTP2_HEADER_KEEP_ALIVE:
|
||||
case h2Consts.HTTP2_HEADER_PROXY_CONNECTION:
|
||||
case h2Consts.HTTP2_HEADER_TRANSFER_ENCODING:
|
||||
return true;
|
||||
case h2Consts.HTTP2_HEADER_TE:
|
||||
return value !== 'trailers';
|
||||
default:
|
||||
return false;
|
||||
case h2Consts.HTTP2_HEADER_CONNECTION:
|
||||
case h2Consts.HTTP2_HEADER_UPGRADE:
|
||||
case h2Consts.HTTP2_HEADER_HOST:
|
||||
case h2Consts.HTTP2_HEADER_HTTP2_SETTINGS:
|
||||
case h2Consts.HTTP2_HEADER_KEEP_ALIVE:
|
||||
case h2Consts.HTTP2_HEADER_PROXY_CONNECTION:
|
||||
case h2Consts.HTTP2_HEADER_TRANSFER_ENCODING:
|
||||
return true;
|
||||
case h2Consts.HTTP2_HEADER_TE:
|
||||
return value !== 'trailers';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1027,9 +1027,9 @@ var handlers = {
|
||||
};
|
||||
var h2Handlers = config.enableH2
|
||||
? {
|
||||
request: toHttp1,
|
||||
upgrade: handlers.upgrade
|
||||
}
|
||||
request: toHttp1,
|
||||
upgrade: handlers.upgrade
|
||||
}
|
||||
: handlers;
|
||||
|
||||
var HTTP_RE = /^(\w+)\s+(\S+)\s+HTTP\/1.\d$/im;
|
||||
|
||||
Reference in New Issue
Block a user