mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 20:52:33 +02:00
support $resp_header(name)
substitution
This commit is contained in:
parent
52d5e2f36d
commit
cebc0c5405
1 changed files with 11 additions and 3 deletions
|
@ -13,9 +13,10 @@ import (
|
||||||
type varReplaceFunc func(string) string
|
type varReplaceFunc func(string) string
|
||||||
|
|
||||||
var (
|
var (
|
||||||
reArg = regexp.MustCompile(`\$arg\([\w-_]+\)`)
|
reArg = regexp.MustCompile(`\$arg\([\w-_]+\)`)
|
||||||
reHeader = regexp.MustCompile(`\$header\([\w-]+\)`)
|
reHeader = regexp.MustCompile(`\$header\([\w-]+\)`)
|
||||||
reStatic = regexp.MustCompile(`\$[\w_]+`)
|
reRespHeader = regexp.MustCompile(`\$resp_header\([\w-]+\)`)
|
||||||
|
reStatic = regexp.MustCompile(`\$[\w_]+`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func varSubsMap(req *Request, resp *Response) map[string]func() string {
|
func varSubsMap(req *Request, resp *Response) map[string]func() string {
|
||||||
|
@ -91,6 +92,13 @@ func varReplacer(req *Request, resp *Response) varReplaceFunc {
|
||||||
return req.Header.Get(header)
|
return req.Header.Get(header)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if resp != nil {
|
||||||
|
s = reRespHeader.ReplaceAllStringFunc(s, func(match string) string {
|
||||||
|
header := http.CanonicalHeaderKey(match[14 : len(match)-1])
|
||||||
|
return resp.Header.Get(header)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Replace static variables
|
// Replace static variables
|
||||||
return reStatic.ReplaceAllStringFunc(s, func(match string) string {
|
return reStatic.ReplaceAllStringFunc(s, func(match string) string {
|
||||||
if fn, ok := pairs[match]; ok {
|
if fn, ok := pairs[match]; ok {
|
||||||
|
|
Loading…
Add table
Reference in a new issue