refactor: refine code

This commit is contained in:
avwo
2022-02-14 13:20:02 +08:00
parent 7f31ec539a
commit dbaff24f3c
40 changed files with 2857 additions and 2394 deletions
+10 -10
View File
@@ -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
View File
@@ -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
View File
@@ -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;