可以配置是否在反向代理中添加X-Real-IP和X-Forwarded-*

This commit is contained in:
GoEdgeLab
2021-01-26 20:29:29 +08:00
parent 493215cdea
commit 1d64e12c15
3 changed files with 93 additions and 45 deletions

View File

@@ -86,6 +86,7 @@ func (this *SettingAction) RunPost(params struct {
RequestURI: reverseProxyConfig.RequestURI, RequestURI: reverseProxyConfig.RequestURI,
StripPrefix: reverseProxyConfig.StripPrefix, StripPrefix: reverseProxyConfig.StripPrefix,
AutoFlush: reverseProxyConfig.AutoFlush, AutoFlush: reverseProxyConfig.AutoFlush,
AddHeaders: reverseProxyConfig.AddHeaders,
}) })
this.Success() this.Success()

View File

@@ -86,6 +86,7 @@ func (this *SettingAction) RunPost(params struct {
RequestURI: reverseProxyConfig.RequestURI, RequestURI: reverseProxyConfig.RequestURI,
StripPrefix: reverseProxyConfig.StripPrefix, StripPrefix: reverseProxyConfig.StripPrefix,
AutoFlush: reverseProxyConfig.AutoFlush, AutoFlush: reverseProxyConfig.AutoFlush,
AddHeaders: reverseProxyConfig.AddHeaders,
}) })
this.Success() this.Success()

View File

@@ -1,50 +1,86 @@
Vue.component("reverse-proxy-box", { Vue.component("reverse-proxy-box", {
props: ["v-reverse-proxy-ref", "v-reverse-proxy-config", "v-is-location", "v-family"], props: ["v-reverse-proxy-ref", "v-reverse-proxy-config", "v-is-location", "v-family"],
data: function () { data: function () {
let reverseProxyRef = this.vReverseProxyRef let reverseProxyRef = this.vReverseProxyRef
if (reverseProxyRef == null) { if (reverseProxyRef == null) {
reverseProxyRef = { reverseProxyRef = {
isPrior: false, isPrior: false,
isOn: false, isOn: false,
reverseProxyId: 0 reverseProxyId: 0
} }
} }
let reverseProxyConfig = this.vReverseProxyConfig let reverseProxyConfig = this.vReverseProxyConfig
if (reverseProxyConfig == null) { if (reverseProxyConfig == null) {
reverseProxyConfig = { reverseProxyConfig = {
requestPath: "", requestPath: "",
stripPrefix: "", stripPrefix: "",
requestURI: "", requestURI: "",
requestHost: "", requestHost: "",
requestHostType: 0 requestHostType: 0,
} addHeaders: []
} }
return { }
reverseProxyRef: reverseProxyRef,
reverseProxyConfig: reverseProxyConfig, let forwardHeaders = [
advancedVisible: false, {
family: this.vFamily name: "X-Real-IP",
} isChecked: false
}, },
watch: { {
"reverseProxyConfig.requestHostType": function (v) { name: "X-Forwarded-For",
let requestHostType = parseInt(v) isChecked: false
if (isNaN(requestHostType)) { },
requestHostType = 0 {
} name: "X-Forwarded-By",
this.reverseProxyConfig.requestHostType = requestHostType isChecked: false
} },
}, {
methods: { name: "X-Forwarded-Host",
isOn: function () { isChecked: false
return (!this.vIsLocation || this.reverseProxyRef.isPrior) && this.reverseProxyRef.isOn },
}, {
changeAdvancedVisible: function (v) { name: "X-Forwarded-Proto",
this.advancedVisible = v isChecked: false
} }
}, ]
template: `<div> forwardHeaders.forEach(function (v) {
v.isChecked = reverseProxyConfig.addHeaders.$contains(v.name)
})
return {
reverseProxyRef: reverseProxyRef,
reverseProxyConfig: reverseProxyConfig,
advancedVisible: false,
family: this.vFamily,
forwardHeaders: forwardHeaders
}
},
watch: {
"reverseProxyConfig.requestHostType": function (v) {
let requestHostType = parseInt(v)
if (isNaN(requestHostType)) {
requestHostType = 0
}
this.reverseProxyConfig.requestHostType = requestHostType
}
},
methods: {
isOn: function () {
return (!this.vIsLocation || this.reverseProxyRef.isPrior) && this.reverseProxyRef.isOn
},
changeAdvancedVisible: function (v) {
this.advancedVisible = v
},
changeAddHeader: function () {
this.reverseProxyConfig.addHeaders = this.forwardHeaders.filter(function (v) {
return v.isChecked
}).map(function (v) {
return v.name
})
}
},
template: `<div>
<input type="hidden" name="reverseProxyRefJSON" :value="JSON.stringify(reverseProxyRef)"/> <input type="hidden" name="reverseProxyRefJSON" :value="JSON.stringify(reverseProxyRef)"/>
<input type="hidden" name="reverseProxyJSON" :value="JSON.stringify(reverseProxyConfig)"/> <input type="hidden" name="reverseProxyJSON" :value="JSON.stringify(reverseProxyConfig)"/>
<table class="ui table selectable definition"> <table class="ui table selectable definition">
@@ -77,6 +113,16 @@ Vue.component("reverse-proxy-box", {
</tbody> </tbody>
<more-options-tbody @change="changeAdvancedVisible" v-if="isOn()"></more-options-tbody> <more-options-tbody @change="changeAdvancedVisible" v-if="isOn()"></more-options-tbody>
<tbody v-show="isOn() && advancedVisible"> <tbody v-show="isOn() && advancedVisible">
<tr v-show="family == null || family == 'http'">
<td>自动添加的Header</td>
<td>
<div>
<div style="width: 20em; float: left; margin-bottom: 1em" v-for="header in forwardHeaders" :key="header.name">
<checkbox v-model="header.isChecked" @input="changeAddHeader">{{header.name}}</checkbox>
</div>
</div>
</td>
</tr>
<tr v-show="family == null || family == 'http'"> <tr v-show="family == null || family == 'http'">
<td>请求URI<em>RequestURI</em></td> <td>请求URI<em>RequestURI</em></td>
<td> <td>