ws earlydata compatible with xray

This commit is contained in:
arm64v8a
2023-05-06 17:43:03 +09:00
parent 51616b5a9a
commit f53d0aba47
2 changed files with 30 additions and 4 deletions

View File

@@ -8,11 +8,24 @@ namespace NekoRay::fmt {
if (network != "tcp") {
QJsonObject transport{{"type", network}};
if (network == "ws") {
if (!path.isEmpty()) transport["path"] = path;
if (!host.isEmpty()) transport["headers"] = QJsonObject{{"Host", host}};
// ws path & ed
auto pathWithoutEd = SubStrBefore(path, "?ed=");
if (!pathWithoutEd.isEmpty()) transport["path"] = pathWithoutEd;
if (pathWithoutEd != path) {
auto ed = SubStrAfter(path, "?ed=").toInt();
if (ed > 0) {
transport["max_early_data"] = ed;
transport["early_data_header_name"] = "Sec-WebSocket-Protocol";
}
}
if (ws_early_data_length > 0) {
transport["max_early_data"] = ws_early_data_length;
transport["early_data_header_name"] = ws_early_data_name;
if (ws_early_data_name.isEmpty()) {
transport["early_data_header_name"] = "Sec-WebSocket-Protocol";
} else {
transport["early_data_header_name"] = ws_early_data_name;
}
}
} else if (network == "http") {
if (!path.isEmpty()) transport["path"] = path;