Skip to content

Commit

Permalink
添加splithttp支持同时更新依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
qist committed Jun 20, 2024
1 parent 79b7c19 commit ad07a19
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.22
1.8.23
104 changes: 100 additions & 4 deletions web/assets/js/model/xray.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ class HttpUpgradeStreamSettings extends XrayCommonClass {
this.headers = headers;
}


addHeader(name, value) {
this.headers.push({ name: name, value: value });
}
Expand Down Expand Up @@ -543,6 +543,52 @@ class HttpUpgradeStreamSettings extends XrayCommonClass {
}
}

class SplitHTTPStreamSettings extends XrayCommonClass {
constructor(path = '/', host = '', headers = [], maxUploadSize = 1, maxConcurrentUploads = 10) {
super();
this.path = path;
this.host = host;
this.headers = headers;
this.maxUploadSize = maxUploadSize;
this.maxConcurrentUploads = maxConcurrentUploads;
}

addHeader(name, value) {
this.headers.push({ name: name, value: value });
}
getHeader(name) {
for (const header of this.headers) {
if (header.name.toLowerCase() === name.toLowerCase()) {
return header.value;
}
}
return null;
}
removeHeader(index) {
this.headers.splice(index, 1);
}

static fromJson(json = {}) {
return new SplitHTTPStreamSettings(
json.path,
json.host,
XrayCommonClass.toHeaders(json.headers),
json.maxUploadSize,
json.maxConcurrentUploads,
);
}

toJson() {
return {
path: this.path,
host: this.host,
headers: XrayCommonClass.toV2Headers(this.headers, false),
maxUploadSize: this.maxUploadSize,
maxConcurrentUploads: this.maxConcurrentUploads,
};
}
}

class TlsStreamSettings extends XrayCommonClass {
constructor(serverName = '',
rejectUnknownSni = false,
Expand Down Expand Up @@ -840,6 +886,7 @@ class StreamSettings extends XrayCommonClass {
quicSettings = new QuicStreamSettings(),
grpcSettings = new GrpcStreamSettings(),
httpupgradeSettings = new HttpUpgradeStreamSettings(),
splithttpSettings = new SplitHTTPStreamSettings(),
sockopt = undefined,
) {
super();
Expand All @@ -854,6 +901,7 @@ class StreamSettings extends XrayCommonClass {
this.quic = quicSettings;
this.grpc = grpcSettings;
this.httpupgrade = httpupgradeSettings;
this.splithttp = splithttpSettings;
this.sockopt = sockopt;
}

Expand Down Expand Up @@ -902,6 +950,7 @@ class StreamSettings extends XrayCommonClass {
QuicStreamSettings.fromJson(json.quicSettings),
GrpcStreamSettings.fromJson(json.grpcSettings),
HttpUpgradeStreamSettings.fromJson(json.httpupgradeSettings),
SplitHTTPStreamSettings.fromJson(json.splithttpSettings),
SockoptStreamSettings.fromJson(json.sockopt),
);
}
Expand All @@ -920,6 +969,7 @@ class StreamSettings extends XrayCommonClass {
quicSettings: network === 'quic' ? this.quic.toJson() : undefined,
grpcSettings: network === 'grpc' ? this.grpc.toJson() : undefined,
httpupgradeSettings: network === 'httpupgrade' ? this.httpupgrade.toJson() : undefined,
splithttpSettings: network === 'splithttp' ? this.splithttp.toJson() : undefined,
sockopt: this.sockopt != undefined ? this.sockopt.toJson() : undefined,
};
}
Expand Down Expand Up @@ -1039,6 +1089,9 @@ class Inbound extends XrayCommonClass {
get isHttpupgrade() {
return this.network === "httpupgrade";
}
get isSplithttp() {
return this.network === "splithttp";
}
// VMess & VLess
get uuid() {
switch (this.protocol) {
Expand Down Expand Up @@ -1115,6 +1168,8 @@ class Inbound extends XrayCommonClass {
return this.stream.http.host[0];
} else if (this.isHttpupgrade) {
return this.stream.httpupgrade.host;
} else if (this.isSplithttp) {
return this.stream.splithttp.host;
}
return null;
}
Expand All @@ -1128,6 +1183,8 @@ class Inbound extends XrayCommonClass {
return this.stream.http.path[0];
} else if (this.isHttpupgrade) {
return this.stream.httpupgrade.path;
} else if (this.isSplithttp) {
return this.stream.splithttp.path;
}
return null;
}
Expand Down Expand Up @@ -1174,6 +1231,7 @@ class Inbound extends XrayCommonClass {
case "quic":
case "grpc":
case "httpupgrade":
case "splithttp":
return true;
default:
return false;
Expand All @@ -1192,7 +1250,7 @@ class Inbound extends XrayCommonClass {
default:
return false;
}
return ['tcp', 'http', 'grpc', 'httpupgrade'].indexOf(this.network) !== -1;
return ['tcp', 'http', 'grpc', 'httpupgrade', 'splithttp'].indexOf(this.network) !== -1;
//return this.network === "tcp";
}

Expand Down Expand Up @@ -1287,17 +1345,25 @@ class Inbound extends XrayCommonClass {
} else if (network === 'grpc') {
path = this.stream.grpc.serviceName;
authority = this.stream.grpc.authority;
if (this.stream.grpc.multiMode){
if (this.stream.grpc.multiMode) {
type = 'multi'
}
}else if (network === 'httpupgrade') {
} else if (network === 'httpupgrade') {
let httpupgrade = this.stream.httpupgrade;
path = httpupgrade.path;
host = httpupgrade.host;
let index = httpupgrade.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (index >= 0) {
host = httpupgrade.headers[index].value;
}
} else if (network === 'splithttp') {
const splithttp = this.stream.splithttp;
path = splithttp.path;
host = splithttp.host;
let index = splithttp.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (index >= 0) {
host = splithttp.headers[index].value;
}
}

if (this.stream.security === 'tls') {
Expand Down Expand Up @@ -1395,6 +1461,16 @@ class Inbound extends XrayCommonClass {
params.set("host", host);
}
break;
case "splithttp":
const splithttp = this.stream.splithttp;
params.set("path", splithttp.path);
params.set("host", splithttp.host);
const splithttpIndex = splithttp.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (splithttpIndex >= 0) {
const host = splithttp.headers[splithttpIndex].value;
params.set("host", host);
}
break;
}

if (this.tls) {
Expand Down Expand Up @@ -1510,6 +1586,16 @@ class Inbound extends XrayCommonClass {
params.set("host", host);
}
break;
case "splithttp":
const splithttp = this.stream.splithttp;
params.set("path", splithttp.path);
params.set("host", splithttp.host);
const splithttpIndex = splithttp.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (splithttpIndex >= 0) {
const host = splithttp.headers[splithttpIndex].value;
params.set("host", host);
}
break;
}

if (security === 'tls') {
Expand Down Expand Up @@ -1616,6 +1702,16 @@ class Inbound extends XrayCommonClass {
params.set("host", host);
}
break;
case "splithttp":
const splithttp = this.stream.splithttp;
params.set("path", splithttp.path);
params.set("host", splithttp.host);
const splithttpIndex = splithttp.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (splithttpIndex >= 0) {
const host = splithttp.headers[splithttpIndex].value;
params.set("host", host);
}
break;
}

if (this.tls) {
Expand Down
5 changes: 5 additions & 0 deletions web/html/xui/form/stream/stream_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<a-select-option value="quic">quic</a-select-option>
<a-select-option value="grpc">grpc</a-select-option>
<a-select-option value="httpupgrade">HTTPUpgrade</a-select-option>
<a-select-option value="splithttp">SplitHTTP</a-select-option>
</a-select>
</a-form-item>
</a-form>
Expand Down Expand Up @@ -49,6 +50,10 @@
{{template "form/streamHTTPUpgrade"}}
</template>

<!-- splithttp -->
<template v-if="inbound.stream.network === 'splithttp'">
{{template "form/streamSplitHTTP"}}
</template>
<!-- sockopt -->
<template>
{{template "form/streamSOCKOPT"}}
Expand Down
33 changes: 33 additions & 0 deletions web/html/xui/form/stream/stream_splithttp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{define "form/streamSplitHTTP"}}
<a-form :colon="false" :label-col="{ md: {span:8} }" :wrapper-col="{ md: {span:14} }">
<a-form-item label='host'>
<a-input v-model.trim="inbound.stream.splithttp.host"></a-input>
</a-form-item>
<a-form-item label='path'>
<a-input v-model.trim="inbound.stream.splithttp.path"></a-input>
</a-form-item>
<a-form-item label="请求头">
<a-row>
<a-button size="small" @click="inbound.stream.splithttp.addHeader('Host', '')">
+
</a-button>
</a-row>
<a-input-group v-for="(header, index) in inbound.stream.splithttp.headers">
<a-input style="width: 50%" v-model.trim="header.name" addon-before="名称"></a-input>
<a-input style="width: 50%" v-model.trim="header.value" addon-before="">
<template slot="addonAfter">
<a-button size="small" @click="inbound.stream.splithttp.removeHeader(index)">
-
</a-button>
</template>
</a-input>
</a-input-group>
</a-form-item>
<a-form-item label="Max Upload Size (MB)">
<a-input-number v-model="inbound.stream.splithttp.maxUploadSize" :min="0"></a-input-number>
</a-form-item>
<a-form-item label="Max Concurrent Upload">
<a-input-number v-model="inbound.stream.splithttp.maxConcurrentUploads" :min="0"></a-input-number>
</a-form-item>
</a-form>
{{end}}

0 comments on commit ad07a19

Please sign in to comment.