Add basic support for VMess h2 & grpc protocols

This commit is contained in:
Tindy X
2021-07-29 02:16:56 +08:00
parent 3ad1c0078e
commit 867602fbea
2 changed files with 26 additions and 4 deletions

View File

@@ -391,6 +391,17 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const string_
if(x.Edge.size())
singleproxy["http-opts"]["headers"]["Edge"].push_back(x.Edge);
break;
case "h2"_hash:
singleproxy["network"] = x.TransferProtocol;
singleproxy["h2-opts"]["path"] = x.Path;
if(x.Host.size())
singleproxy["h2-opts"]["host"].push_back(x.Host);
break;
case "grpc"_hash:
singleproxy["network"] = x.TransferProtocol;
singleproxy["servername"] = x.Host;
singleproxy["grpc-opts"]["grpc-service-name"] = x.Path;
break;
default:
continue;
}

View File

@@ -960,17 +960,28 @@ void explodeClash(Node yamlnode, std::vector<Proxy> &nodes)
singleproxy["alterId"] >>= aid;
singleproxy["cipher"] >>= cipher;
net = singleproxy["network"].IsDefined() ? safe_as<std::string>(singleproxy["network"]) : "tcp";
if(net == "http")
switch(hash_(net))
{
case "http"_hash:
singleproxy["http-opts"]["path"][0] >>= path;
singleproxy["http-opts"]["headers"]["Host"][0] >>= host;
edge.clear();
}
else
{
break;
case "ws"_hash:
path = singleproxy["ws-path"].IsDefined() ? safe_as<std::string>(singleproxy["ws-path"]) : "/";
singleproxy["ws-headers"]["Host"] >>= host;
singleproxy["ws-headers"]["Edge"] >>= edge;
break;
case "h2"_hash:
singleproxy["h2-opts"]["path"] >>= path;
singleproxy["h2-opts"]["host"][0] >>= host;
edge.clear();
break;
case "grpc"_hash:
singleproxy["servername"] >>= host;
singleproxy["grpc-opts"]["grpc-service-name"] >>= path;
edge.clear();
break;
}
tls = safe_as<std::string>(singleproxy["tls"]) == "true" ? "tls" : "";