Skip to content

Commit

Permalink
sockopt acceptProxyProtocol for h2 , gRPC #773
Browse files Browse the repository at this point in the history
  • Loading branch information
MHSanaei committed Jul 29, 2023
1 parent eaec9e5 commit 6066edd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
41 changes: 35 additions & 6 deletions web/assets/js/model/xray.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,10 @@ class HttpStreamSettings extends XrayCommonClass {
constructor(
path='/',
host=[''],
sockopt={acceptProxyProtocol: false}
) {
super();
this.path = path;
this.host = host.length === 0 ? [''] : host;
this.sockopt = sockopt;
}

addHost(host) {
Expand All @@ -417,7 +415,6 @@ class HttpStreamSettings extends XrayCommonClass {
return {
path: this.path,
host: host,
sockopt: this.sockopt,
}
}
}
Expand Down Expand Up @@ -455,12 +452,10 @@ class GrpcStreamSettings extends XrayCommonClass {
constructor(
serviceName="",
multiMode=false,
sockopt={acceptProxyProtocol: false}
) {
super();
this.serviceName = serviceName;
this.multiMode = multiMode;
this.sockopt = sockopt;
}

static fromJson(json={}) {
Expand All @@ -475,7 +470,6 @@ class GrpcStreamSettings extends XrayCommonClass {
return {
serviceName: this.serviceName,
multiMode: this.multiMode,
sockopt: this.sockopt
}
}
}
Expand Down Expand Up @@ -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 {
constructor(network='tcp',
security='none',
Expand All @@ -819,6 +834,7 @@ class StreamSettings extends XrayCommonClass {
httpSettings=new HttpStreamSettings(),
quicSettings=new QuicStreamSettings(),
grpcSettings=new GrpcStreamSettings(),
sockopt = new SockoptStreamSettings(),
) {
super();
this.network = network;
Expand All @@ -832,6 +848,7 @@ class StreamSettings extends XrayCommonClass {
this.http = httpSettings;
this.quic = quicSettings;
this.grpc = grpcSettings;
this.sockopt = sockopt;
}

get isTls() {
Expand Down Expand Up @@ -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={}) {

return new StreamSettings(
Expand All @@ -885,6 +912,7 @@ class StreamSettings extends XrayCommonClass {
HttpStreamSettings.fromJson(json.httpSettings),
QuicStreamSettings.fromJson(json.quicSettings),
GrpcStreamSettings.fromJson(json.grpcSettings),
SockoptStreamSettings.fromJson(json.sockopt),
);
}

Expand All @@ -902,6 +930,7 @@ class StreamSettings extends XrayCommonClass {
httpSettings: network === 'http' ? this.http.toJson() : undefined,
quicSettings: network === 'quic' ? this.quic.toJson() : undefined,
grpcSettings: network === 'grpc' ? this.grpc.toJson() : undefined,
sockopt: this.isSockopt ? this.sockopt.toJson() : undefined,
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion web/html/xui/form/stream/stream_grpc.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{define "form/streamGRPC"}}
<a-form layout="inline">
<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>
<br>
<a-form-item label="ServiceName">
Expand Down
2 changes: 1 addition & 1 deletion web/html/xui/form/stream/stream_http.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{define "form/streamHTTP"}}
<a-form layout="inline">
<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>
<br>
<a-form-item label='{{ i18n "path" }}'>
Expand Down

0 comments on commit 6066edd

Please sign in to comment.