Skip to content

Commit

Permalink
fix http2 network type
Browse files Browse the repository at this point in the history
  • Loading branch information
cocomeow committed Dec 8, 2021
1 parent 72a302c commit 20ba983
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion i18n/across_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@
<context>
<name>across::NodeFormModel</name>
<message>
<location filename="../../../ACross/src/view_models/nodeformmodel.cpp" line="462"/>
<location filename="../../../ACross/src/view_models/nodeformmodel.cpp" line="467"/>
<source>custom configuration encoding to url is not supported</source>
<translation>未支持自定义配置编码到链接格式</translation>
</message>
Expand Down
15 changes: 11 additions & 4 deletions src/models/serializetools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ SerializeTools::vmessBase64Decode(const std::string &url_str) {
}

if (root.contains("net")) {
stream->set_network(root["net"].get<std::string>());
if (root["net"].get<std::string>() == "h2") {
stream->set_network("http");
} else {
stream->set_network(root["net"].get<std::string>());
}

do {
if (stream->network() == "tcp") {
Expand All @@ -317,7 +321,7 @@ SerializeTools::vmessBase64Decode(const std::string &url_str) {
break;
}

if (stream->network() == "h2") {
if (stream->network() == "http") {
auto http2 = stream->mutable_httpsettings();

if (root.contains("host")) {
Expand Down Expand Up @@ -440,10 +444,13 @@ SerializeTools::vmessBase64Encode(const URLMetaObject &meta) {
root["scy"] = user.security();

if (stream.IsInitialized()) {
root["net"] = stream.network();
if (stream.network() == "h2" || stream.network() == "http")
root["net"] = "h2";
else
root["net"] = stream.network();

do {
if (stream.network() == "h2" && stream.has_httpsettings()) {
if (stream.network() == "http" && stream.has_httpsettings()) {
const auto &http2 = stream.httpsettings();
std::string hosts;

Expand Down
11 changes: 8 additions & 3 deletions src/view_models/nodeformmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,13 @@ bool NodeFormModel::setVMessOutboud(NodeInfo &node, const QVariantMap &values) {
user->set_security(values.value("security").toString().toStdString());

auto stream = outbound->mutable_streamsettings();
if (values.contains("network"))
stream->set_network(values.value("network").toString().toStdString());
if (values.contains("network")) {
if (values.value("network").toString() == "h2")
stream->set_network("http");
else
stream->set_network(
values.value("network").toString().toStdString());
}

if (values.contains("enableTLS") && values.value("enableTLS").toBool()) {
stream->set_security("tls");
Expand All @@ -288,7 +293,7 @@ bool NodeFormModel::setVMessOutboud(NodeInfo &node, const QVariantMap &values) {
}

do {
if (stream->network() == "h2") {
if (stream->network() == "http") {
auto http2 = stream->mutable_httpsettings();

if (values.contains("host")) {
Expand Down
5 changes: 4 additions & 1 deletion src/views/typescripts/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function networkSelectToggle(currentIndex, components, control = null) {
switch (currentIndex) {
case 0: // none
break;
case 1:
case 1: // h2
hostLabel.visible = true;
hostLabel.text = "Host";
hostText.visible = true;
Expand Down Expand Up @@ -105,6 +105,9 @@ function visibleChangeToggle(visible, components, model = null) {
let streamSettings = raw["streamSettings"];
if (streamSettings.hasOwnProperty("network") && networkSelect !== null) {
let network = streamSettings["network"];
if (network === "http") {
network = "h2";
}
networkSelect.currentIndex = networkSelect.find(network);
switch (network) {
case "h2":
Expand Down
7 changes: 5 additions & 2 deletions src/views/typescripts/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function networkSelectToggle(currentIndex: number, components: any, control: any
switch (currentIndex) {
case 0: // none
break
case 1:
case 1: // h2
hostLabel.visible = true
hostLabel.text = "Host"
hostText.visible = true
Expand Down Expand Up @@ -122,8 +122,11 @@ function visibleChangeToggle(visible: boolean, components: any, model: any = nul
if (streamSettings.hasOwnProperty("network") && networkSelect !== null) {
let network = streamSettings["network"]

networkSelect.currentIndex = networkSelect.find(network)
if (network === "http") {
network = "h2"
}

networkSelect.currentIndex = networkSelect.find(network)
switch (network) {
case "h2":
if (streamSettings.hasOwnProperty("httpSettings")) {
Expand Down

0 comments on commit 20ba983

Please sign in to comment.