sockopt acceptProxyProtocol for h2 , gRPC #773

This commit is contained in:
MHSanaei 2023-07-29 15:52:02 +03:30
parent eaec9e54ad
commit 6066edd510
3 changed files with 37 additions and 8 deletions

View File

@ -387,12 +387,10 @@ class HttpStreamSettings extends XrayCommonClass {
constructor( constructor(
path='/', path='/',
host=[''], host=[''],
sockopt={acceptProxyProtocol: false}
) { ) {
super(); super();
this.path = path; this.path = path;
this.host = host.length === 0 ? [''] : host; this.host = host.length === 0 ? [''] : host;
this.sockopt = sockopt;
} }
addHost(host) { addHost(host) {
@ -417,7 +415,6 @@ class HttpStreamSettings extends XrayCommonClass {
return { return {
path: this.path, path: this.path,
host: host, host: host,
sockopt: this.sockopt,
} }
} }
} }
@ -455,12 +452,10 @@ class GrpcStreamSettings extends XrayCommonClass {
constructor( constructor(
serviceName="", serviceName="",
multiMode=false, multiMode=false,
sockopt={acceptProxyProtocol: false}
) { ) {
super(); super();
this.serviceName = serviceName; this.serviceName = serviceName;
this.multiMode = multiMode; this.multiMode = multiMode;
this.sockopt = sockopt;
} }
static fromJson(json={}) { static fromJson(json={}) {
@ -475,7 +470,6 @@ class GrpcStreamSettings extends XrayCommonClass {
return { return {
serviceName: this.serviceName, serviceName: this.serviceName,
multiMode: this.multiMode, multiMode: this.multiMode,
sockopt: this.sockopt
} }
} }
} }
@ -807,6 +801,27 @@ RealityStreamSettings.Settings = class extends XrayCommonClass {
} }
}; };
class SockoptStreamSettings extends XrayCommonClass {
constructor(
acceptProxyProtocol = false,
) {
super();
this.acceptProxyProtocol = acceptProxyProtocol;
}
static fromJson(json = {}) {
return new SockoptStreamSettings(
json.acceptProxyProtocol,
);
}
toJson() {
return {
acceptProxyProtocol: this.acceptProxyProtocol,
};
}
}
class StreamSettings extends XrayCommonClass { class StreamSettings extends XrayCommonClass {
constructor(network='tcp', constructor(network='tcp',
security='none', security='none',
@ -819,6 +834,7 @@ class StreamSettings extends XrayCommonClass {
httpSettings=new HttpStreamSettings(), httpSettings=new HttpStreamSettings(),
quicSettings=new QuicStreamSettings(), quicSettings=new QuicStreamSettings(),
grpcSettings=new GrpcStreamSettings(), grpcSettings=new GrpcStreamSettings(),
sockopt = new SockoptStreamSettings(),
) { ) {
super(); super();
this.network = network; this.network = network;
@ -832,6 +848,7 @@ class StreamSettings extends XrayCommonClass {
this.http = httpSettings; this.http = httpSettings;
this.quic = quicSettings; this.quic = quicSettings;
this.grpc = grpcSettings; this.grpc = grpcSettings;
this.sockopt = sockopt;
} }
get isTls() { get isTls() {
@ -871,6 +888,16 @@ class StreamSettings extends XrayCommonClass {
} }
} }
get isSockopt() {
return ['http', 'grpc'].indexOf(this.network) !== -1;
}
set isSockopt(isSockopt) {
if (isSockopt) {
return ['http', 'grpc'].indexOf(this.network) !== -1;
}
}
static fromJson(json={}) { static fromJson(json={}) {
return new StreamSettings( return new StreamSettings(
@ -885,6 +912,7 @@ class StreamSettings extends XrayCommonClass {
HttpStreamSettings.fromJson(json.httpSettings), HttpStreamSettings.fromJson(json.httpSettings),
QuicStreamSettings.fromJson(json.quicSettings), QuicStreamSettings.fromJson(json.quicSettings),
GrpcStreamSettings.fromJson(json.grpcSettings), GrpcStreamSettings.fromJson(json.grpcSettings),
SockoptStreamSettings.fromJson(json.sockopt),
); );
} }
@ -902,6 +930,7 @@ class StreamSettings extends XrayCommonClass {
httpSettings: network === 'http' ? this.http.toJson() : undefined, httpSettings: network === 'http' ? this.http.toJson() : undefined,
quicSettings: network === 'quic' ? this.quic.toJson() : undefined, quicSettings: network === 'quic' ? this.quic.toJson() : undefined,
grpcSettings: network === 'grpc' ? this.grpc.toJson() : undefined, grpcSettings: network === 'grpc' ? this.grpc.toJson() : undefined,
sockopt: this.isSockopt ? this.sockopt.toJson() : undefined,
}; };
} }
} }

View File

@ -1,7 +1,7 @@
{{define "form/streamGRPC"}} {{define "form/streamGRPC"}}
<a-form layout="inline"> <a-form layout="inline">
<a-form-item label="AcceptProxyProtocol"> <a-form-item label="AcceptProxyProtocol">
<a-switch v-model="inbound.stream.grpc.sockopt.acceptProxyProtocol"></a-switch> <a-switch v-model="inbound.stream.sockopt.acceptProxyProtocol"></a-switch>
</a-form-item> </a-form-item>
<br> <br>
<a-form-item label="ServiceName"> <a-form-item label="ServiceName">

View File

@ -1,7 +1,7 @@
{{define "form/streamHTTP"}} {{define "form/streamHTTP"}}
<a-form layout="inline"> <a-form layout="inline">
<a-form-item label="AcceptProxyProtocol"> <a-form-item label="AcceptProxyProtocol">
<a-switch v-model="inbound.stream.http.sockopt.acceptProxyProtocol"></a-switch> <a-switch v-model="inbound.stream.sockopt.acceptProxyProtocol"></a-switch>
</a-form-item> </a-form-item>
<br> <br>
<a-form-item label='{{ i18n "path" }}'> <a-form-item label='{{ i18n "path" }}'>