feat: gRPC 支持 authority

This commit is contained in:
xream
2024-12-05 00:52:11 +08:00
parent dda8113a42
commit 4ea84118c4
9 changed files with 27 additions and 1 deletions

View File

@@ -380,6 +380,7 @@ function URI_VMess() {
proxy[`${proxy.network}-opts`] = {
'grpc-service-name': getIfNotBlank(transportPath),
'_grpc-type': getIfNotBlank(params.type),
'_grpc-authority': getIfNotBlank(params.authority),
};
} else {
const opts = {
@@ -515,6 +516,9 @@ function URI_VLESS() {
}
if (params.serviceName) {
opts[`${proxy.network}-service-name`] = params.serviceName;
if (['grpc'].includes(proxy.network) && params.authority) {
opts['_grpc-authority'] = params.authority;
}
} else if (isShadowrocket && params.path) {
if (!['ws', 'http', 'h2'].includes(proxy.network)) {
opts[`${proxy.network}-service-name`] = params.path;

View File

@@ -101,6 +101,7 @@ params = "?" head:param tail:("&"@param)* {
proxy[proxy.network + '-opts'] = {
'grpc-service-name': params["serviceName"],
'_grpc-type': params["mode"],
'_grpc-authority': params["authority"],
};
} else {
if (params["path"]) {

View File

@@ -99,6 +99,7 @@ params = "?" head:param tail:("&"@param)* {
proxy[proxy.network + '-opts'] = {
'grpc-service-name': params["serviceName"],
'_grpc-type': params["mode"],
'_grpc-authority': params["authority"],
};
} else {
if (params["path"]) {

View File

@@ -175,6 +175,7 @@ export default function Clash_Producer() {
proxy[`${proxy.network}-opts`]
) {
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
delete proxy[`${proxy.network}-opts`]['_grpc-authority'];
}
return proxy;
});

View File

@@ -190,6 +190,7 @@ export default function ClashMeta_Producer() {
proxy[`${proxy.network}-opts`]
) {
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
delete proxy[`${proxy.network}-opts`]['_grpc-authority'];
}
return proxy;
});

View File

@@ -193,6 +193,7 @@ export default function ShadowRocket_Producer() {
proxy[`${proxy.network}-opts`]
) {
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
delete proxy[`${proxy.network}-opts`]['_grpc-authority'];
}
return proxy;
});

View File

@@ -289,6 +289,7 @@ export default function Stash_Producer() {
proxy[`${proxy.network}-opts`]
) {
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
delete proxy[`${proxy.network}-opts`]['_grpc-authority'];
}
return proxy;
});

View File

@@ -134,6 +134,8 @@ export default function URI_Producer() {
result.type =
proxy[`${proxy.network}-opts`]?.['_grpc-type'] ||
'gun';
result.host =
proxy[`${proxy.network}-opts`]?.['_grpc-authority'];
}
}
result = 'vmess://' + Base64.encode(JSON.stringify(result));
@@ -196,6 +198,13 @@ export default function URI_Producer() {
vlessTransport += `&mode=${encodeURIComponent(
proxy[`${proxy.network}-opts`]?.['_grpc-type'] || 'gun',
)}`;
const authority =
proxy[`${proxy.network}-opts`]?.['_grpc-authority'];
if (authority) {
vlessTransport += `&authority=${encodeURIComponent(
authority,
)}`;
}
}
let vlessTransportServiceName =
@@ -261,11 +270,18 @@ export default function URI_Producer() {
proxy[`${proxy.network}-opts`]?.[
`${proxy.network}-service-name`
];
let trojanTransportAuthority =
proxy[`${proxy.network}-opts`]?.['_grpc-authority'];
if (trojanTransportServiceName) {
trojanTransport += `&serviceName=${encodeURIComponent(
trojanTransportServiceName,
)}`;
}
if (trojanTransportAuthority) {
trojanTransport += `&authority=${encodeURIComponent(
trojanTransportAuthority,
)}`;
}
trojanTransport += `&mode=${encodeURIComponent(
proxy[`${proxy.network}-opts`]?.['_grpc-type'] ||
'gun',