fix: h2 -> http

fix: edit profile ui
This commit is contained in:
arm64v8a
2022-11-09 09:34:03 +09:00
parent f4744e7c7e
commit 7c47a616e4
8 changed files with 38 additions and 27 deletions

View File

@@ -6,9 +6,7 @@ namespace NekoRay::fmt {
// https://sing-box.sagernet.org/configuration/shared/v2ray-transport
if (network != "tcp") {
QJsonObject transport{
{"type", network.replace("h2", "http")},
};
QJsonObject transport{{"type", network},};
if (network == "ws") {
if (!path.isEmpty()) transport["path"] = path;
if (!host.isEmpty()) transport["headers"] = QJsonObject{{"Host", host}};

View File

@@ -22,11 +22,11 @@ namespace NekoRay::fmt {
ws["earlyDataHeaderName"] = ws_early_data_name;
}
streamSettings["wsSettings"] = ws;
} else if (network == "h2") {
QJsonObject h2;
if (!path.isEmpty()) h2["path"] = path;
if (!host.isEmpty()) h2["host"] = QList2QJsonArray(host.split(","));
streamSettings["httpSettings"] = h2;
} else if (network == "http") {
QJsonObject http;
if (!path.isEmpty()) http["path"] = path;
if (!host.isEmpty()) http["host"] = QList2QJsonArray(host.split(","));
streamSettings["httpSettings"] = http;
} else if (network == "grpc") {
QJsonObject grpc;
if (!path.isEmpty()) grpc["serviceName"] = path;

View File

@@ -33,9 +33,9 @@ namespace NekoRay::fmt {
if (!name.isEmpty()) url.setFragment(UrlSafe_encode(name));
if (!stream->sni.isEmpty()) query.addQueryItem("sni", stream->sni);
query.addQueryItem("security", "tls");
query.addQueryItem("type", stream->network.replace("h2", "http"));
query.addQueryItem("type", stream->network);
if (stream->network == "ws" || stream->network == "h2") {
if (stream->network == "ws" || stream->network == "http") {
if (!stream->path.isEmpty()) query.addQueryItem("path", stream->path);
if (!stream->host.isEmpty()) query.addQueryItem("host", stream->host);
} else if (stream->network == "grpc") {

View File

@@ -52,7 +52,7 @@ namespace NekoRay::fmt {
password = url.userName();
if (serverPort == -1) serverPort = 443;
stream->network = GetQueryValue(query, "type", "tcp").replace("http", "h2");
stream->network = GetQueryValue(query, "type", "tcp");
stream->security = GetQueryValue(query, "security", "tls");
auto sni1 = GetQueryValue(query, "sni");
auto sni2 = GetQueryValue(query, "peer");
@@ -64,7 +64,7 @@ namespace NekoRay::fmt {
if (stream->network == "ws") {
stream->path = GetQueryValue(query, "path", "");
stream->host = GetQueryValue(query, "host", "");
} else if (stream->network == "h2") {
} else if (stream->network == "http") {
stream->path = GetQueryValue(query, "path", "");
stream->host = GetQueryValue(query, "host", "").replace("|", ",");
} else if (stream->network == "grpc") {
@@ -119,7 +119,7 @@ namespace NekoRay::fmt {
stream->path = objN["path"].toString();
stream->sni = objN["sni"].toString();
stream->header_type = objN["type"].toString();
auto net = objN["net"].toString().replace("http", "h2");
auto net = objN["net"].toString();
if (!net.isEmpty()) stream->network = net;
auto scy = objN["scy"].toString();
if (!scy.isEmpty()) security = scy;

View File

@@ -8,7 +8,7 @@ namespace NekoRay::fmt {
QString network = "tcp";
QString security = "";
QString packet_encoding = "";
// ws/h2/grpc/tcp-http
// ws/http/grpc/tcp-http
QString path = "";
QString host = "";
// kcp/quic/tcp-http

View File

@@ -250,7 +250,7 @@ namespace NekoRay::sub {
bean->uuid = Node2QString(proxy["uuid"]);
bean->aid = Node2Int(proxy["alterId"]);
bean->security = Node2QString(proxy["cipher"]);
bean->stream->network = Node2QString(proxy["network"], "tcp");
bean->stream->network = Node2QString(proxy["network"], "tcp").replace("h2", "http");
bean->stream->sni = FIRST_OR_SECOND(Node2QString(proxy["sni"]), Node2QString(proxy["servername"]));
if (Node2Bool(proxy["tls"])) bean->stream->security = "tls";
if (Node2Bool(proxy["skip-cert-verify"])) bean->stream->allow_insecure = true;
@@ -273,7 +273,7 @@ namespace NekoRay::sub {
auto h2 = NodeChild(proxy, {"h2-opts", "h2-opt"});
if (h2.IsMap()) {
auto hosts = ws["host"];
auto hosts = h2["host"];
for (auto host: hosts) {
bean->stream->host = Node2QString(host);
break;

View File

@@ -30,7 +30,8 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
network_title_base = ui->network_box->title();
connect(ui->network, &QComboBox::currentTextChanged, this, [=](const QString &txt) {
ui->network_box->setTitle(network_title_base.arg(txt));
if (txt == "tcp" || txt == "quic") {
// 传输设置
if (txt == "tcp" || (!IS_NEKO_BOX && txt == "quic")) {
ui->header_type->setVisible(true);
ui->header_type_l->setVisible(true);
ui->path->setVisible(true);
@@ -44,7 +45,7 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
ui->path_l->setVisible(true);
ui->host->setVisible(false);
ui->host_l->setVisible(false);
} else if (txt == "ws" || txt == "h2") {
} else if (txt == "ws" || txt == "http") {
ui->header_type->setVisible(false);
ui->header_type_l->setVisible(false);
ui->path->setVisible(true);
@@ -59,6 +60,7 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
ui->host->setVisible(false);
ui->host_l->setVisible(false);
}
// 传输设置 ED
if (txt == "ws") {
ui->ws_early_data_length->setVisible(true);
ui->ws_early_data_length_l->setVisible(true);
@@ -70,6 +72,17 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
ui->ws_early_data_name->setVisible(false);
ui->ws_early_data_name_l->setVisible(false);
}
// 传输设置 for NekoBox
if (IS_NEKO_BOX) {
ui->header_type->setVisible(false);
ui->header_type_l->setVisible(false);
}
// 传输设置 是否可见
int networkBoxVisible = 0;
for (auto label: ui->network_box->findChildren<QLabel *>()) {
if (!label->isHidden()) networkBoxVisible++;
}
ui->network_box->setVisible(networkBoxVisible);
ADJUST_SIZE
});
ui->network->removeItem(0);
@@ -83,6 +96,7 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
}
ADJUST_SIZE
});
emit ui->security->currentTextChanged(ui->security->currentText());
// 确定模式和 ent
newEnt = _type != "";
@@ -240,10 +254,8 @@ void DialogEditProfile::typeSelected(const QString &newType) {
}
}
// 设置 for NekoBox
if (IS_NEKO_BOX) {
ui->header_type->hide();
ui->header_type_l->hide();
//
if (type == "vmess" || type == "vless") {
ui->packet_encoding->setVisible(true);
ui->packet_encoding_l->setVisible(true);
@@ -267,7 +279,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
ui->security->setVisible(false);
ui->security_l->setVisible(false);
}
//
// 设置 是否可见
int streamBoxVisible = 0;
for (auto label: ui->stream_box->findChildren<QLabel *>()) {
if (!label->isHidden()) streamBoxVisible++;
@@ -275,7 +287,8 @@ void DialogEditProfile::typeSelected(const QString &newType) {
ui->stream_box->setVisible(streamBoxVisible);
}
auto rightNoBox = (ui->stream_box->isHidden() && ui->security_box->isHidden() && ui->network_box->isHidden());
// 载入 type 之后,有些类型没有右边的设置
auto rightNoBox = (ui->stream_box->isHidden() && ui->network_box->isHidden() && ui->security_box->isHidden());
if (rightNoBox && !ui->right_all_w->isHidden()) {
ui->right_all_w->setVisible(false);
}
@@ -285,7 +298,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
// 第一次显示
if (isHidden()) {
show();
runOnUiThread([=] { show(); }, this);
}
}

View File

@@ -240,7 +240,7 @@
</item>
<item>
<property name="text">
<string notr="true">h2</string>
<string notr="true">http</string>
</property>
</item>
<item>
@@ -314,7 +314,7 @@
<item row="1" column="0">
<widget class="QLabel" name="path_l">
<property name="toolTip">
<string notr="true">http path (ws/h2/伪装http)
<string notr="true">http path (ws/http/伪装http)
serviceName (gRPC)
key (QUIC)</string>
</property>
@@ -329,7 +329,7 @@ key (QUIC)</string>
<item row="2" column="0">
<widget class="QLabel" name="host_l">
<property name="toolTip">
<string notr="true">http host (ws/h2/伪装http)
<string notr="true">http host (ws/http/伪装http)
security (QUIC)</string>
</property>
<property name="text">