update ws and httpupgrade

This commit is contained in:
Alireza Ahmadi
2024-04-09 19:51:51 +02:00
parent e1696c9fd3
commit 649c96ef16
5 changed files with 67 additions and 63 deletions

View File

@@ -194,14 +194,14 @@ class WsStreamSettings extends CommonClass {
static fromJson(json={}) {
return new WsStreamSettings(
json.path,
json.headers && !ObjectUtil.isEmpty(json.headers.Host) ? json.headers.Host : '',
json.host,
);
}
toJson() {
return {
path: this.path,
headers: ObjectUtil.isEmpty(this.host) ? undefined : {Host: this.host},
host: this.host,
};
}
}

View File

@@ -332,10 +332,11 @@ class KcpStreamSettings extends XrayCommonClass {
}
class WsStreamSettings extends XrayCommonClass {
constructor(acceptProxyProtocol=false, path='/', headers=[]) {
constructor(acceptProxyProtocol=false, path='/', host='', headers=[]) {
super();
this.acceptProxyProtocol = acceptProxyProtocol;
this.path = path;
this.host = host;
this.headers = headers;
}
@@ -343,15 +344,6 @@ class WsStreamSettings extends XrayCommonClass {
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);
}
@@ -360,6 +352,7 @@ class WsStreamSettings extends XrayCommonClass {
return new WsStreamSettings(
json.acceptProxyProtocol,
json.path,
json.host,
XrayCommonClass.toHeaders(json.headers),
);
}
@@ -368,6 +361,7 @@ class WsStreamSettings extends XrayCommonClass {
return {
acceptProxyProtocol: this.acceptProxyProtocol,
path: this.path,
host: this.host,
headers: XrayCommonClass.toV2Headers(this.headers, false),
};
}
@@ -435,7 +429,7 @@ class QuicStreamSettings extends XrayCommonClass {
}
class GrpcStreamSettings extends XrayCommonClass {
constructor(serviceName="", authority="", multiMode=false) {
constructor(serviceName='', authority='', multiMode=false) {
super();
this.serviceName = serviceName;
this.authority = authority;
@@ -456,11 +450,20 @@ class GrpcStreamSettings extends XrayCommonClass {
}
class HttpUpgradeStreamSettings extends XrayCommonClass {
constructor(acceptProxyProtocol=false, path='/', host='') {
constructor(acceptProxyProtocol=false, path='/', host='', headers=[]) {
super();
this.acceptProxyProtocol = acceptProxyProtocol;
this.path = path;
this.host = host;
this.headers = headers;
}
addHeader(name, value) {
this.headers.push({ name: name, value: value });
}
removeHeader(index) {
this.headers.splice(index, 1);
}
static fromJson(json={}) {
@@ -468,6 +471,7 @@ class HttpUpgradeStreamSettings extends XrayCommonClass {
json.acceptProxyProtocol,
json.path,
json.host,
XrayCommonClass.toHeaders(json.headers),
);
}
@@ -476,6 +480,7 @@ class HttpUpgradeStreamSettings extends XrayCommonClass {
acceptProxyProtocol: this.acceptProxyProtocol,
path: this.path,
host: this.host,
headers: XrayCommonClass.toV2Headers(this.headers, false),
};
}
}
@@ -930,7 +935,7 @@ class Inbound extends XrayCommonClass {
case Protocols.SHADOWSOCKS:
return this.settings.method;
default:
return "";
return '';
}
}
get isSSMultiUser() {
@@ -943,17 +948,15 @@ class Inbound extends XrayCommonClass {
get serverName() {
if (this.stream.isTls) return this.stream.tls.sni;
if (this.stream.isReality) return this.stream.reality.serverNames;
return "";
return '';
}
get host() {
if (this.isTcp) {
return this.stream.tcp.request.getHeader("Host");
} else if (this.isWs) {
return this.stream.ws.getHeader("Host");
} else if (this.isH2) {
return this.stream.http.host[0];
} else if (this.isHttpupgrade) {
} else if (this.isHttpupgrade || this.isWs) {
return this.stream.httpupgrade.host;
}
return null;
@@ -1067,10 +1070,7 @@ class Inbound extends XrayCommonClass {
} else if (network === 'ws') {
let ws = this.stream.ws;
obj.path = ws.path;
let index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (index >= 0) {
obj.host = ws.headers[index].value;
}
obj.host = ws.host;
} else if (network === 'http') {
obj.net = 'h2';
obj.path = this.stream.http.path;
@@ -1137,11 +1137,7 @@ class Inbound extends XrayCommonClass {
case "ws":
const ws = this.stream.ws;
params.set("path", ws.path);
const index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (index >= 0) {
const host = ws.headers[index].value;
params.set("host", host);
}
params.set("host", httpupgrade.host);
break;
case "http":
const http = this.stream.http;
@@ -1163,10 +1159,10 @@ class Inbound extends XrayCommonClass {
}
break;
case "httpupgrade":
const httpupgrade = this.stream.httpupgrade;
params.set("path", httpupgrade.path);
params.set("host", httpupgrade.host);
break;
const httpupgrade = this.stream.httpupgrade;
params.set("path", httpupgrade.path);
params.set("host", httpupgrade.host);
break;
}
if (security === 'tls') {
@@ -1245,11 +1241,7 @@ class Inbound extends XrayCommonClass {
case "ws":
const ws = this.stream.ws;
params.set("path", ws.path);
const index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (index >= 0) {
const host = ws.headers[index].value;
params.set("host", host);
}
params.set("host", httpupgrade.host);
break;
case "http":
const http = this.stream.http;
@@ -1271,10 +1263,10 @@ class Inbound extends XrayCommonClass {
}
break;
case "httpupgrade":
const httpupgrade = this.stream.httpupgrade;
params.set("path", httpupgrade.path);
params.set("host", httpupgrade.host);
break;
const httpupgrade = this.stream.httpupgrade;
params.set("path", httpupgrade.path);
params.set("host", httpupgrade.host);
break;
}
if (security === 'tls') {
@@ -1332,11 +1324,7 @@ class Inbound extends XrayCommonClass {
case "ws":
const ws = this.stream.ws;
params.set("path", ws.path);
const index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (index >= 0) {
const host = ws.headers[index].value;
params.set("host", host);
}
params.set("host", httpupgrade.host);
break;
case "http":
const http = this.stream.http;
@@ -1358,10 +1346,10 @@ class Inbound extends XrayCommonClass {
}
break;
case "httpupgrade":
const httpupgrade = this.stream.httpupgrade;
params.set("path", httpupgrade.path);
params.set("host", httpupgrade.host);
break;
const httpupgrade = this.stream.httpupgrade;
params.set("path", httpupgrade.path);
params.set("host", httpupgrade.host);
break;
}
if (security === 'tls') {
@@ -1629,7 +1617,7 @@ Inbound.VmessSettings.Vmess = class extends XrayCommonClass {
);
}
get _expiryTime() {
if (this.expiryTime === 0 || this.expiryTime === "") {
if (this.expiryTime === 0 || this.expiryTime === '') {
return null;
}
if (this.expiryTime < 0){
@@ -1639,7 +1627,7 @@ Inbound.VmessSettings.Vmess = class extends XrayCommonClass {
}
set _expiryTime(t) {
if (t == null || t === "") {
if (t == null || t === '') {
this.expiryTime = 0;
} else {
this.expiryTime = t.valueOf();
@@ -1722,7 +1710,7 @@ Inbound.VLESSSettings.VLESS = class extends XrayCommonClass {
}
get _expiryTime() {
if (this.expiryTime === 0 || this.expiryTime === "") {
if (this.expiryTime === 0 || this.expiryTime === '') {
return null;
}
if (this.expiryTime < 0){
@@ -1732,7 +1720,7 @@ Inbound.VLESSSettings.VLESS = class extends XrayCommonClass {
}
set _expiryTime(t) {
if (t == null || t === "") {
if (t == null || t === '') {
this.expiryTime = 0;
} else {
this.expiryTime = t.valueOf();
@@ -1747,7 +1735,7 @@ Inbound.VLESSSettings.VLESS = class extends XrayCommonClass {
}
};
Inbound.VLESSSettings.Fallback = class extends XrayCommonClass {
constructor(name="", alpn='', path='', dest='', xver=0) {
constructor(name='', alpn='', path='', dest='', xver=0) {
super();
this.name = name;
this.alpn = alpn;
@@ -1856,7 +1844,7 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
}
get _expiryTime() {
if (this.expiryTime === 0 || this.expiryTime === "") {
if (this.expiryTime === 0 || this.expiryTime === '') {
return null;
}
if (this.expiryTime < 0){
@@ -1866,7 +1854,7 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
}
set _expiryTime(t) {
if (t == null || t === "") {
if (t == null || t === '') {
this.expiryTime = 0;
} else {
this.expiryTime = t.valueOf();
@@ -1883,7 +1871,7 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
};
Inbound.TrojanSettings.Fallback = class extends XrayCommonClass {
constructor(name="", alpn='', path='', dest='', xver=0) {
constructor(name='', alpn='', path='', dest='', xver=0) {
super();
this.name = name;
this.alpn = alpn;
@@ -1998,7 +1986,7 @@ Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass {
}
get _expiryTime() {
if (this.expiryTime === 0 || this.expiryTime === "") {
if (this.expiryTime === 0 || this.expiryTime === '') {
return null;
}
if (this.expiryTime < 0){
@@ -2008,7 +1996,7 @@ Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass {
}
set _expiryTime(t) {
if (t == null || t === "") {
if (t == null || t === '') {
this.expiryTime = 0;
} else {
this.expiryTime = t.valueOf();

View File

@@ -291,7 +291,7 @@
<a-input v-model="outbound.stream.ws.host"></a-input>
</a-form-item>
<a-form-item label='{{ i18n "path" }}'>
<a-form-item><a-input v-model.trim="outbound.stream.ws.path"></a-input>
<a-input v-model.trim="outbound.stream.ws.path"></a-input>
</a-form-item>
</template>
@@ -348,8 +348,8 @@
<a-input v-model="outbound.stream.httpupgrade.host"></a-input>
</a-form-item>
<a-form-item label='{{ i18n "path" }}'>
<a-form-item><a-input v-model.trim="outbound.stream.httpupgrade.path"></a-input>
</a-form-item>
<a-input v-model.trim="outbound.stream.httpupgrade.path"></a-input>
</a-form-item>
</template>
</template>

View File

@@ -9,5 +9,18 @@
<a-form-item label='{{ i18n "host" }}'>
<a-input v-model.trim="inbound.stream.httpupgrade.host"></a-input>
</a-form-item>
<a-form-item label='{{ i18n "pages.inbounds.stream.tcp.requestHeader" }}'>
<a-button size="small" @click="inbound.stream.ws.addHeader()">+</a-button>
</a-form-item>
<a-form-item :wrapper-col="{span:24}">
<a-input-group compact v-for="(header, index) in inbound.stream.ws.headers">
<a-input style="width: 50%" v-model.trim="header.name" placeholder='{{ i18n "pages.inbounds.stream.general.name"}}'>
<template slot="addonBefore" style="margin: 0;">[[ index+1 ]]</template>
</a-input>
<a-input style="width: 50%" v-model.trim="header.value" placeholder='{{ i18n "pages.inbounds.stream.general.value" }}'>
<a-button slot="addonAfter" size="small" @click="inbound.stream.ws.removeHeader(index)">-</a-button>
</a-input>
</a-input-group>
</a-form-item>
</a-form>
{{end}}

View File

@@ -6,6 +6,9 @@
<a-form-item label='{{ i18n "path" }}'>
<a-input v-model.trim="inbound.stream.ws.path"></a-input>
</a-form-item>
<a-form-item label='{{ i18n "host" }}'>
<a-input v-model.trim="inbound.stream.ws.host"></a-input>
</a-form-item>
<a-form-item label='{{ i18n "pages.inbounds.stream.tcp.requestHeader" }}'>
<a-button size="small" @click="inbound.stream.ws.addHeader()">+</a-button>
</a-form-item>