mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-05 14:20:25 +08:00
HTTP Header:实现请求方法、域名、状态码等限制,实现内容替换功能
This commit is contained in:
@@ -467,7 +467,7 @@ func (this *CreateAction) RunPost(params struct {
|
||||
AccessLogJSON: []byte(`{
|
||||
"isPrior": false,
|
||||
"isOn": true,
|
||||
"fields": [6, 7],
|
||||
"fields": [1, 2, 6, 7],
|
||||
"status1": true,
|
||||
"status2": true,
|
||||
"status3": true,
|
||||
|
||||
@@ -19,8 +19,10 @@ func (this *CreateSetPopupAction) Init() {
|
||||
|
||||
func (this *CreateSetPopupAction) RunGet(params struct {
|
||||
HeaderPolicyId int64
|
||||
Type string
|
||||
}) {
|
||||
this.Data["headerPolicyId"] = params.HeaderPolicyId
|
||||
this.Data["type"] = params.Type
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -30,6 +32,14 @@ func (this *CreateSetPopupAction) RunPost(params struct {
|
||||
Name string
|
||||
Value string
|
||||
|
||||
StatusListJSON []byte
|
||||
MethodsJSON []byte
|
||||
DomainsJSON []byte
|
||||
ShouldAppend bool
|
||||
DisableRedirect bool
|
||||
ShouldReplace bool
|
||||
ReplaceValuesJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
// 日志
|
||||
@@ -51,10 +61,57 @@ func (this *CreateSetPopupAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
// status list
|
||||
var statusList = []int32{}
|
||||
if len(params.StatusListJSON) > 0 {
|
||||
err = json.Unmarshal(params.StatusListJSON, &statusList)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
var methods = []string{}
|
||||
if len(params.MethodsJSON) > 0 {
|
||||
err = json.Unmarshal(params.MethodsJSON, &methods)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// domains
|
||||
var domains = []string{}
|
||||
if len(params.DomainsJSON) > 0 {
|
||||
err = json.Unmarshal(params.DomainsJSON, &domains)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// replace values
|
||||
var replaceValues = []*shared.HTTPHeaderReplaceValue{}
|
||||
if len(params.ReplaceValuesJSON) > 0 {
|
||||
err = json.Unmarshal(params.ReplaceValuesJSON, &replaceValues)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 创建Header
|
||||
createHeaderResp, err := this.RPC().HTTPHeaderRPC().CreateHTTPHeader(this.AdminContext(), &pb.CreateHTTPHeaderRequest{
|
||||
Name: params.Name,
|
||||
Value: params.Value,
|
||||
Status: statusList,
|
||||
Methods: methods,
|
||||
Domains: domains,
|
||||
ShouldAppend: params.ShouldAppend,
|
||||
DisableRedirect: params.DisableRedirect,
|
||||
ShouldReplace: params.ShouldReplace,
|
||||
ReplaceValuesJSON: params.ReplaceValuesJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -35,26 +35,6 @@ func (this *DeleteAction) RunPost(params struct {
|
||||
}
|
||||
|
||||
switch params.Type {
|
||||
case "addHeader":
|
||||
result := []*shared.HTTPHeaderRef{}
|
||||
for _, h := range policyConfig.AddHeaderRefs {
|
||||
if h.HeaderId != params.HeaderId {
|
||||
result = append(result, h)
|
||||
}
|
||||
}
|
||||
resultJSON, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicyAddingHeaders(this.AdminContext(), &pb.UpdateHTTPHeaderPolicyAddingHeadersRequest{
|
||||
HeaderPolicyId: params.HeaderPolicyId,
|
||||
HeadersJSON: resultJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
case "setHeader":
|
||||
result := []*shared.HTTPHeaderRef{}
|
||||
for _, h := range policyConfig.SetHeaderRefs {
|
||||
@@ -75,46 +55,6 @@ func (this *DeleteAction) RunPost(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
case "replace":
|
||||
result := []*shared.HTTPHeaderRef{}
|
||||
for _, h := range policyConfig.ReplaceHeaderRefs {
|
||||
if h.HeaderId != params.HeaderId {
|
||||
result = append(result, h)
|
||||
}
|
||||
}
|
||||
resultJSON, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicyReplacingHeaders(this.AdminContext(), &pb.UpdateHTTPHeaderPolicyReplacingHeadersRequest{
|
||||
HeaderPolicyId: params.HeaderPolicyId,
|
||||
HeadersJSON: resultJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
case "addTrailer":
|
||||
result := []*shared.HTTPHeaderRef{}
|
||||
for _, h := range policyConfig.AddTrailerRefs {
|
||||
if h.HeaderId != params.HeaderId {
|
||||
result = append(result, h)
|
||||
}
|
||||
}
|
||||
resultJSON, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicyAddingTrailers(this.AdminContext(), &pb.UpdateHTTPHeaderPolicyAddingTrailersRequest{
|
||||
HeaderPolicyId: params.HeaderPolicyId,
|
||||
HeadersJSON: resultJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
|
||||
@@ -20,9 +20,11 @@ func (this *UpdateSetPopupAction) Init() {
|
||||
func (this *UpdateSetPopupAction) RunGet(params struct {
|
||||
HeaderPolicyId int64
|
||||
HeaderId int64
|
||||
Type string
|
||||
}) {
|
||||
this.Data["headerPolicyId"] = params.HeaderPolicyId
|
||||
this.Data["headerId"] = params.HeaderId
|
||||
this.Data["type"] = params.Type
|
||||
|
||||
headerResp, err := this.RPC().HTTPHeaderRPC().FindEnabledHTTPHeaderConfig(this.AdminContext(), &pb.FindEnabledHTTPHeaderConfigRequest{HeaderId: params.HeaderId})
|
||||
if err != nil {
|
||||
@@ -45,6 +47,14 @@ func (this *UpdateSetPopupAction) RunPost(params struct {
|
||||
Name string
|
||||
Value string
|
||||
|
||||
StatusListJSON []byte
|
||||
MethodsJSON []byte
|
||||
DomainsJSON []byte
|
||||
ShouldAppend bool
|
||||
DisableRedirect bool
|
||||
ShouldReplace bool
|
||||
ReplaceValuesJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
// 日志
|
||||
@@ -54,10 +64,57 @@ func (this *UpdateSetPopupAction) RunPost(params struct {
|
||||
Field("name", params.Name).
|
||||
Require("请输入Header名称")
|
||||
|
||||
// status list
|
||||
var statusList = []int32{}
|
||||
if len(params.StatusListJSON) > 0 {
|
||||
err := json.Unmarshal(params.StatusListJSON, &statusList)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
var methods = []string{}
|
||||
if len(params.MethodsJSON) > 0 {
|
||||
err := json.Unmarshal(params.MethodsJSON, &methods)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// domains
|
||||
var domains = []string{}
|
||||
if len(params.DomainsJSON) > 0 {
|
||||
err := json.Unmarshal(params.DomainsJSON, &domains)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// replace values
|
||||
var replaceValues = []*shared.HTTPHeaderReplaceValue{}
|
||||
if len(params.ReplaceValuesJSON) > 0 {
|
||||
err := json.Unmarshal(params.ReplaceValuesJSON, &replaceValues)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
_, err := this.RPC().HTTPHeaderRPC().UpdateHTTPHeader(this.AdminContext(), &pb.UpdateHTTPHeaderRequest{
|
||||
HeaderId: params.HeaderId,
|
||||
Name: params.Name,
|
||||
Value: params.Value,
|
||||
Status: statusList,
|
||||
Methods: methods,
|
||||
Domains: domains,
|
||||
ShouldAppend: params.ShouldAppend,
|
||||
DisableRedirect: params.DisableRedirect,
|
||||
ShouldReplace: params.ShouldReplace,
|
||||
ReplaceValuesJSON: params.ReplaceValuesJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
Vue.component("http-header-policy-box", {
|
||||
props: ["v-request-header-policy", "v-request-header-ref", "v-response-header-policy", "v-response-header-ref", "v-params", "v-is-location", "v-is-group", "v-has-group-request-config", "v-has-group-response-config", "v-group-setting-url"],
|
||||
data: function () {
|
||||
let type = "request"
|
||||
let type = "response"
|
||||
let hash = window.location.hash
|
||||
if (hash == "#response") {
|
||||
type = "response"
|
||||
if (hash == "#request") {
|
||||
type = "request"
|
||||
}
|
||||
|
||||
// ref
|
||||
@@ -72,7 +72,7 @@ Vue.component("http-header-policy-box", {
|
||||
window.location.reload()
|
||||
},
|
||||
addSettingHeader: function (policyId) {
|
||||
teaweb.popup("/servers/server/settings/headers/createSetPopup?" + this.vParams + "&headerPolicyId=" + policyId, {
|
||||
teaweb.popup("/servers/server/settings/headers/createSetPopup?" + this.vParams + "&headerPolicyId=" + policyId + "&type=" + this.type, {
|
||||
callback: function () {
|
||||
teaweb.successRefresh("保存成功")
|
||||
}
|
||||
@@ -86,7 +86,7 @@ Vue.component("http-header-policy-box", {
|
||||
})
|
||||
},
|
||||
updateSettingPopup: function (policyId, headerId) {
|
||||
teaweb.popup("/servers/server/settings/headers/updateSetPopup?" + this.vParams + "&headerPolicyId=" + policyId + "&headerId=" + headerId, {
|
||||
teaweb.popup("/servers/server/settings/headers/updateSetPopup?" + this.vParams + "&headerPolicyId=" + policyId + "&headerId=" + headerId+ "&type=" + this.type, {
|
||||
callback: function () {
|
||||
teaweb.successRefresh("保存成功")
|
||||
}
|
||||
@@ -118,8 +118,8 @@ Vue.component("http-header-policy-box", {
|
||||
},
|
||||
template: `<div>
|
||||
<div class="ui menu tabular small">
|
||||
<a class="item" :class="{active:type == 'request'}" @click.prevent="selectType('request')">请求Header<span v-if="requestSettingHeaders.length > 0">({{requestSettingHeaders.length}})</span></a>
|
||||
<a class="item" :class="{active:type == 'response'}" @click.prevent="selectType('response')">响应Header<span v-if="responseSettingHeaders.length > 0">({{responseSettingHeaders.length}})</span></a>
|
||||
<a class="item" :class="{active:type == 'request'}" @click.prevent="selectType('request')">请求Header<span v-if="requestSettingHeaders.length > 0">({{requestSettingHeaders.length}})</span></a>
|
||||
</div>
|
||||
|
||||
<div class="margin"></div>
|
||||
@@ -152,7 +152,17 @@ Vue.component("http-header-policy-box", {
|
||||
</tr>
|
||||
</thead>
|
||||
<tr v-for="header in requestSettingHeaders">
|
||||
<td class="five wide">{{header.name}}</td>
|
||||
<td class="five wide">
|
||||
{{header.name}}
|
||||
<div>
|
||||
<span v-if="header.status != null && header.status.codes != null && !header.status.always"><grey-label v-for="code in header.status.codes" :key="code">{{code}}</grey-label></span>
|
||||
<span v-if="header.methods != null && header.methods.length > 0"><grey-label v-for="method in header.methods" :key="method">{{method}}</grey-label></span>
|
||||
<span v-if="header.domains != null && header.domains.length > 0"><grey-label v-for="domain in header.domains" :key="domain">{{domain}}</grey-label></span>
|
||||
<grey-label v-if="header.shouldAppend">附加</grey-label>
|
||||
<grey-label v-if="header.disableRedirect">跳转禁用</grey-label>
|
||||
<grey-label v-if="header.shouldReplace && header.replaceValues != null && header.replaceValues.length > 0">替换</grey-label>
|
||||
</div>
|
||||
</td>
|
||||
<td>{{header.value}}</td>
|
||||
<td><a href="" @click.prevent="updateSettingPopup(vRequestHeaderPolicy.id, header.id)">修改</a> <a href="" @click.prevent="deleteHeader(vRequestHeaderPolicy.id, 'setHeader', header.id)">删除</a> </td>
|
||||
</tr>
|
||||
@@ -201,7 +211,17 @@ Vue.component("http-header-policy-box", {
|
||||
</tr>
|
||||
</thead>
|
||||
<tr v-for="header in responseSettingHeaders">
|
||||
<td class="five wide">{{header.name}}</td>
|
||||
<td class="five wide">
|
||||
{{header.name}}
|
||||
<div>
|
||||
<span v-if="header.status != null && header.status.codes != null && !header.status.always"><grey-label v-for="code in header.status.codes" :key="code">{{code}}</grey-label></span>
|
||||
<span v-if="header.methods != null && header.methods.length > 0"><grey-label v-for="method in header.methods" :key="method">{{method}}</grey-label></span>
|
||||
<span v-if="header.domains != null && header.domains.length > 0"><grey-label v-for="domain in header.domains" :key="domain">{{domain}}</grey-label></span>
|
||||
<grey-label v-if="header.shouldAppend">附加</grey-label>
|
||||
<grey-label v-if="header.disableRedirect">跳转禁用</grey-label>
|
||||
<grey-label v-if="header.shouldReplace && header.replaceValues != null && header.replaceValues.length > 0">替换</grey-label>
|
||||
</div>
|
||||
</td>
|
||||
<td>{{header.value}}</td>
|
||||
<td><a href="" @click.prevent="updateSettingPopup(vResponseHeaderPolicy.id, header.id)">修改</a> <a href="" @click.prevent="deleteHeader(vResponseHeaderPolicy.id, 'setHeader', header.id)">删除</a> </td>
|
||||
</tr>
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
Vue.component("http-header-replace-values", {
|
||||
props: ["v-replace-values"],
|
||||
data: function () {
|
||||
let values = this.vReplaceValues
|
||||
if (values == null) {
|
||||
values = []
|
||||
}
|
||||
return {
|
||||
values: values,
|
||||
isAdding: false,
|
||||
addingValue: {"pattern": "", "replacement": "", "isCaseInsensitive": false, "isRegexp": false}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add: function () {
|
||||
this.isAdding = true
|
||||
let that = this
|
||||
setTimeout(function () {
|
||||
that.$refs.pattern.focus()
|
||||
})
|
||||
},
|
||||
remove: function (index) {
|
||||
this.values.$remove(index)
|
||||
},
|
||||
confirm: function () {
|
||||
let that = this
|
||||
if (this.addingValue.pattern.length == 0) {
|
||||
teaweb.warn("替换前内容不能为空", function () {
|
||||
that.$refs.pattern.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.values.push(this.addingValue)
|
||||
this.cancel()
|
||||
},
|
||||
cancel: function () {
|
||||
this.isAdding = false
|
||||
this.addingValue = {"pattern": "", "replacement": "", "isCaseInsensitive": false, "isRegexp": false}
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
<input type="hidden" name="replaceValuesJSON" :value="JSON.stringify(values)"/>
|
||||
<div>
|
||||
<div v-for="(value, index) in values" class="ui label small" style="margin-bottom: 0.5em">
|
||||
<var>{{value.pattern}}</var><sup v-if="value.isCaseInsensitive" title="不区分大小写"><i class="icon info tiny"></i></sup> => <var v-if="value.replacement.length > 0">{{value.replacement}}</var><var v-else><span class="small grey">[空]</span></var>
|
||||
<a href="" @click.prevent="remove(index)" title="删除"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="isAdding">
|
||||
<table class="ui table">
|
||||
<tr>
|
||||
<td class="title">替换前内容 *</td>
|
||||
<td><input type="text" v-model="addingValue.pattern" placeholder="替换前内容" ref="pattern" @keyup.enter="confirm()" @keypress.enter.prevent="1"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>替换后内容</td>
|
||||
<td><input type="text" v-model="addingValue.replacement" placeholder="替换后内容" @keyup.enter="confirm()" @keypress.enter.prevent="1"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>是否忽略大小写</td>
|
||||
<td>
|
||||
<checkbox v-model="addingValue.isCaseInsensitive"></checkbox>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div>
|
||||
<button type="button" class="ui button tiny" @click.prevent="confirm">确定</button>
|
||||
<a href="" title="取消" @click.prevent="cancel"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!isAdding">
|
||||
<button type="button" class="ui button tiny" @click.prevent="add">+</button>
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
81
web/public/js/components/server/http-methods-box.js
Normal file
81
web/public/js/components/server/http-methods-box.js
Normal file
@@ -0,0 +1,81 @@
|
||||
// 请求方法列表
|
||||
Vue.component("http-methods-box", {
|
||||
props: ["v-methods"],
|
||||
data: function () {
|
||||
let methods = this.vMethods
|
||||
if (methods == null) {
|
||||
methods = []
|
||||
}
|
||||
return {
|
||||
methods: methods,
|
||||
isAdding: false,
|
||||
addingMethod: ""
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add: function () {
|
||||
this.isAdding = true
|
||||
let that = this
|
||||
setTimeout(function () {
|
||||
that.$refs.addingMethod.focus()
|
||||
}, 100)
|
||||
},
|
||||
confirm: function () {
|
||||
let that = this
|
||||
|
||||
// 删除其中的空格
|
||||
this.addingMethod = this.addingMethod.replace(/\s/g, "").toUpperCase()
|
||||
|
||||
if (this.addingMethod.length == 0) {
|
||||
teaweb.warn("请输入要添加的请求方法", function () {
|
||||
that.$refs.addingMethod.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 是否已经存在
|
||||
if (this.methods.$contains(this.addingMethod)) {
|
||||
teaweb.warn("此请求方法已经存在,无需重复添加", function () {
|
||||
that.$refs.addingMethod.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.methods.push(this.addingMethod)
|
||||
this.cancel()
|
||||
},
|
||||
remove: function (index) {
|
||||
this.methods.$remove(index)
|
||||
},
|
||||
cancel: function () {
|
||||
this.isAdding = false
|
||||
this.addingMethod = ""
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
<input type="hidden" name="methodsJSON" :value="JSON.stringify(methods)"/>
|
||||
<div v-if="methods.length > 0">
|
||||
<span class="ui label small basic" v-for="(method, index) in methods">
|
||||
{{method}}
|
||||
<a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
|
||||
</span>
|
||||
<div class="ui divider"></div>
|
||||
</div>
|
||||
<div v-if="isAdding">
|
||||
<div class="ui fields">
|
||||
<div class="ui field">
|
||||
<input type="text" v-model="addingMethod" @keyup.enter="confirm()" @keypress.enter.prevent="1" ref="addingMethod" placeholder="如GET" size="10"/>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<button class="ui button tiny" type="button" @click.prevent="confirm">确定</button>
|
||||
<a href="" title="取消" @click.prevent="cancel"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<p class="comment">格式为大写,比如<code-label>GET</code-label>、<code-label>POST</code-label>等。</p>
|
||||
<div class="ui divider"></div>
|
||||
</div>
|
||||
<div style="margin-top: 0.5em" v-if="!isAdding">
|
||||
<button class="ui button tiny" type="button" @click.prevent="add">+</button>
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
89
web/public/js/components/server/http-status-box.js
Normal file
89
web/public/js/components/server/http-status-box.js
Normal file
@@ -0,0 +1,89 @@
|
||||
// 请求方法列表
|
||||
Vue.component("http-status-box", {
|
||||
props: ["v-status-list"],
|
||||
data: function () {
|
||||
let statusList = this.vStatusList
|
||||
if (statusList == null) {
|
||||
statusList = []
|
||||
}
|
||||
return {
|
||||
statusList: statusList,
|
||||
isAdding: false,
|
||||
addingStatus: ""
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add: function () {
|
||||
this.isAdding = true
|
||||
let that = this
|
||||
setTimeout(function () {
|
||||
that.$refs.addingStatus.focus()
|
||||
}, 100)
|
||||
},
|
||||
confirm: function () {
|
||||
let that = this
|
||||
|
||||
// 删除其中的空格
|
||||
this.addingStatus = this.addingStatus.replace(/\s/g, "").toUpperCase()
|
||||
|
||||
if (this.addingStatus.length == 0) {
|
||||
teaweb.warn("请输入要添加的状态码", function () {
|
||||
that.$refs.addingStatus.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 是否已经存在
|
||||
if (this.statusList.$contains(this.addingStatus)) {
|
||||
teaweb.warn("此状态码已经存在,无需重复添加", function () {
|
||||
that.$refs.addingStatus.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 格式
|
||||
if (!this.addingStatus.match(/^\d{3}$/)) {
|
||||
teaweb.warn("请输入正确的状态码", function () {
|
||||
that.$refs.addingStatus.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.statusList.push(parseInt(this.addingStatus, 10))
|
||||
this.cancel()
|
||||
},
|
||||
remove: function (index) {
|
||||
this.statusList.$remove(index)
|
||||
},
|
||||
cancel: function () {
|
||||
this.isAdding = false
|
||||
this.addingStatus = ""
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
<input type="hidden" name="statusListJSON" :value="JSON.stringify(statusList)"/>
|
||||
<div v-if="statusList.length > 0">
|
||||
<span class="ui label small basic" v-for="(status, index) in statusList">
|
||||
{{status}}
|
||||
<a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
|
||||
</span>
|
||||
<div class="ui divider"></div>
|
||||
</div>
|
||||
<div v-if="isAdding">
|
||||
<div class="ui fields">
|
||||
<div class="ui field">
|
||||
<input type="text" v-model="addingStatus" @keyup.enter="confirm()" @keypress.enter.prevent="1" ref="addingStatus" placeholder="如200" size="3" maxlength="3" style="width: 5em"/>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<button class="ui button tiny" type="button" @click.prevent="confirm">确定</button>
|
||||
<a href="" title="取消" @click.prevent="cancel"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<p class="comment">格式为三位数字,比如<code-label>200</code-label>、<code-label>404</code-label>等。</p>
|
||||
<div class="ui divider"></div>
|
||||
</div>
|
||||
<div style="margin-top: 0.5em" v-if="!isAdding">
|
||||
<button class="ui button tiny" type="button" @click.prevent="add">+</button>
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
@@ -121,7 +121,7 @@ p.margin {
|
||||
.main table td {
|
||||
vertical-align: top;
|
||||
}
|
||||
.main table td.color-border {
|
||||
table td.color-border {
|
||||
border-left: 1px #276ac6 solid !important;
|
||||
}
|
||||
.main table td.vertical-top {
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["@layout_popup.less"],"names":[],"mappings":";AACA;EACC,WAAA;;AAGD;EACC,aAAA;;AAGD;EACC,qBAAA;;AAGD,CAAC;AAAW,CAAC,SAAS;AAAQ,CAAC,SAAS;AAAS,IAAI;EACpD,sBAAA;;AAGD,CAAC;AAAU,IAAI;AAAU,IAAI;EAC5B,cAAA;;AAGD,IAAI;AAAO,KAAK;AAAO,CAAC;EACvB,sBAAA;;AAGD,CAAC;EACA,iBAAA;;AAGD,IAAI;AAAM,GAAG;EACZ,cAAA;;AAGD,GAAG,IAAI;EACN,mBAAmB,8CAAnB;;AAGD;EACC,uBAAA;;AAGD,MAAM;EACL,sBAAA;;AAGD,MAAM;EACL,sBAAA;;AAGD,MAAM;EACL,sBAAA;;AAGD,MAAO;AAAI,MAAO;EACjB,2BAAA;;AAGD,CAAC;AAAU,GAAG;EACb,yBAAA;EACA,kBAAA;EACA,mBAAA;;AAGD,CAAC,QAAS;AAAI,GAAG,QAAS;EACzB,6BAAA;;AAGD;EACC,mBAAA;EACA,2BAAA;EACA,gBAAA;EACA,uBAAA;;AAGD,GAAG;AAAS,CAAC;EACZ,eAAA;;;AAID,GAAG;EACF,UAAA;;AAGD,GAAG;EACF,YAAA;;AAGD,GAAG;EACF,UAAA;;AAGD,GAAG;EACF,WAAA;;;AAID,MAAM;EACL,aAAA;;;AAID;EACC,kBAAA;EACA,UAAA;EACA,UAAA;EACA,mBAAA;EACA,kBAAA;EACA,UAAA;;AASD,mBANqC;EACpC;IACC,SAAA;;;AAIF,KAAK;EACJ,SAAA;;AAGD,KAAK;EACJ,UAAA;;AASD,mBANqC;EACpC,KAAK;IACJ,SAAA;;;AAIF,KAAM,MAAM,GAAE;EACb,WAAA;;AAGD,KAAM,MAAM,GAAE;EACb,WAAA;;AAGD,KAAM,MAAM;EACX,mBAAA;;AAGD,KAAM,MAAM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OD,WAAY,MAAK;EAChB,wBAAA;EACA,2BAAA;;AAGD,WAAY;EACX,wBAAA;EACA,2BAAA;;AAGD,YAAa,MAAK;EACjB,wBAAA;EACA,2BAAA;;AAGD,YAAa,MAAK,KAAM;EACvB,kBAAA;;AAGD,YAAa;EACZ,wBAAA;;AAGD,KAAM;EACL,aAAA;;;AAID,IAAI;AAAQ,GAAG;EACd,yBAAA;;AAGD,GAAG;EACF,8BAAA;;;AAID,QAAS;EACR,WAAA;EACA,kBAAA;;;AAID,SAAU,MAAM;AAAG,SAAU;EAC5B,2BAAA;;;AAID;EACC,eAAA;EAEA,2BAAA;;AAHD,KAKC;EACC,qBAAA;EACA,mBAAA;EACA,WAAA;EACA,iBAAA;EACA,SAAA;EACA,gBAAA;EACA,sBAAA;EACA,cAAA;;AAbF,KAgBC,EAAC;EACA,8BAAA;EACA,YAAA;;AAlBF,KAqBC,EAAC;EACA,gBAAA;;AAKF;EACC,kBAAA;;AAGD,cAAc;AAAQ,aAAa;AAAQ,YAAY;EACtD,iCAAA;;AAGD;AAAgB;AAAe;EAC9B,iCAAA;;AAGD;EACC,2BAAA;;AAID,KAAK;EACJ,oCAAA;;AAID,QAAQ;EACP,4BAA4B,wBAA5B;EACA,2BAAA","file":"@layout_popup.css"}
|
||||
@@ -140,7 +140,7 @@ div.margin, p.margin {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.main table td.color-border {
|
||||
table td.color-border {
|
||||
border-left: 1px #276ac6 solid !important;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<input type="hidden" name="headerPolicyId" :value="headerPolicyId"/>
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">名称<em>(Name)</em></td>
|
||||
<td class="title">名称<em>(Name)</em> *</td>
|
||||
<td>
|
||||
<input type="text" name="name" value="" maxlength="200" placeholder="类似于Server、Content-Type之类" ref="focus"/>
|
||||
<p class="comment">请注意名称的大小写,如无特殊需求,Header名称的格式通常为<code-label>Xxx</code-label>或者<code-label>Xxx-Yyy</code-label>。</p>
|
||||
@@ -18,6 +18,53 @@
|
||||
<p class="comment">可以包含请求变量。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><more-options-indicator>更多选项</more-options-indicator></td>
|
||||
</tr>
|
||||
<tbody v-show="moreOptionsVisible">
|
||||
<tr v-show="type == 'response'">
|
||||
<td>支持的状态码</td>
|
||||
<td>
|
||||
<http-status-box></http-status-box>
|
||||
<p class="comment">只有在设置响应Header时才会起作用。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>支持的请求方法</td>
|
||||
<td><http-methods-box></http-methods-box></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>支持的域名</td>
|
||||
<td><domains-box></domains-box></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>只附加不替换</td>
|
||||
<td>
|
||||
<checkbox name="shouldAppend"></checkbox>
|
||||
<p class="comment">选中后表示如果已经存在同名的Header,则只会附加在原有的Header之后,不会覆盖。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-show="type == 'response'">
|
||||
<td>不在跳转时启用</td>
|
||||
<td>
|
||||
<checkbox name="disableRedirect"></checkbox>
|
||||
<p class="comment">选中后表示在30X跳转时不启用当前Header。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="color-border">启用内容替换</td>
|
||||
<td>
|
||||
<checkbox name="shouldReplace" v-model="shouldReplace"></checkbox>
|
||||
<p class="comment">可以替换原有Header中的内容。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-show="shouldReplace">
|
||||
<td class="color-border">替换内容</td>
|
||||
<td>
|
||||
<http-header-replace-values></http-header-replace-values>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<submit-btn></submit-btn>
|
||||
</form>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Tea.context(function () {
|
||||
this.shouldReplace = false
|
||||
})
|
||||
@@ -6,7 +6,7 @@
|
||||
<input type="hidden" name="headerId" :value="headerId"/>
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">名称<em>(Name)</em></td>
|
||||
<td class="title">名称<em>(Name)</em> *</td>
|
||||
<td>
|
||||
<input type="text" name="name" value="" v-model="headerConfig.name" maxlength="200" placeholder="类似于Server、Content-Type之类" ref="focus"/>
|
||||
<p class="comment">请注意名称的大小写,如无特殊需求,Header名称的格式通常为<code-label>Xxx</code-label>或者<code-label>Xxx-Yyy</code-label>。</p>
|
||||
@@ -19,6 +19,52 @@
|
||||
<p class="comment">可以包含请求变量。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><more-options-indicator>更多选项</more-options-indicator></td>
|
||||
</tr>
|
||||
<tbody v-show="moreOptionsVisible">
|
||||
<tr v-show="type == 'response'">
|
||||
<td>支持的状态码</td>
|
||||
<td>
|
||||
<http-status-box :v-status-list="statusList"></http-status-box>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>支持的请求方法</td>
|
||||
<td><http-methods-box :v-methods="headerConfig.methods"></http-methods-box></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>支持的域名</td>
|
||||
<td><domains-box :v-domains="headerConfig.domains"></domains-box></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>只附加不替换</td>
|
||||
<td>
|
||||
<checkbox name="shouldAppend" v-model="headerConfig.shouldAppend"></checkbox>
|
||||
<p class="comment">选中后表示如果已经存在同名的Header,则只会附加在原有的Header之后,不会覆盖。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-show="type == 'response'">
|
||||
<td>不在跳转时启用</td>
|
||||
<td>
|
||||
<checkbox name="disableRedirect" v-model="headerConfig.disableRedirect"></checkbox>
|
||||
<p class="comment">选中后表示在30X跳转时不启用当前Header。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="color-border">启用内容替换</td>
|
||||
<td>
|
||||
<checkbox name="shouldReplace" v-model="shouldReplace"></checkbox>
|
||||
<p class="comment">可以替换原有Header中的内容。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-show="shouldReplace">
|
||||
<td class="color-border">替换内容</td>
|
||||
<td>
|
||||
<http-header-replace-values :v-replace-values="headerConfig.replaceValues"></http-header-replace-values>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<submit-btn></submit-btn>
|
||||
</form>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
Tea.context(function () {
|
||||
this.shouldReplace = this.headerConfig.shouldReplace
|
||||
this.statusList = []
|
||||
if (this.headerConfig.status != null && this.headerConfig.status.codes != null) {
|
||||
this.statusList = this.headerConfig.status.codes
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user