${response.header.NAME}变量中的NAME可以是非标准格式

This commit is contained in:
刘祥超
2023-05-19 18:10:20 +08:00
parent 973e67acdb
commit 82aff804a6

View File

@@ -866,7 +866,23 @@ func (this *HTTPRequest) Format(source string) string {
}
switch suffix[:dotIndex] {
case "header":
return this.writer.Header().Get(suffix[dotIndex+1:])
var headers = this.writer.Header()
var headerKey = suffix[dotIndex+1:]
v, found := headers[headerKey]
if found {
if len(v) == 0 {
return ""
}
return v[0]
}
var canonicalHeaderKey = http.CanonicalHeaderKey(headerKey)
if canonicalHeaderKey != headerKey {
v = headers[canonicalHeaderKey]
if len(v) > 0 {
return v[0]
}
}
return ""
}
}