Adding one-time method override (#3373)

This commit is contained in:
Mzack9999 2023-03-04 07:57:26 +01:00 committed by GitHub
parent d9e953acfa
commit d7ac306bdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -148,7 +148,6 @@ func (p *Page) hasModificationRules() bool {
if containsAnyModificationActionType(rule.Action) {
return true
}
}
return false
}

View File

@ -8,6 +8,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"time"
"github.com/go-rod/rod"
@ -92,6 +93,7 @@ func (p *Page) ExecuteActions(baseURL *url.URL, actions []*Action) (map[string]s
}
type rule struct {
*sync.Once
Action ActionType
Part string
Args map[string]string
@ -215,12 +217,12 @@ func (p *Page) ActionSetBody(act *Action, out map[string]string /*TODO review un
}
// ActionSetMethod executes an SetMethod action.
func (p *Page) ActionSetMethod(act *Action, out map[string]string /*TODO review unused parameter*/) error {
func (p *Page) ActionSetMethod(act *Action, out map[string]string) error {
in := p.getActionArgWithDefaultValues(act, "part")
args := make(map[string]string)
args["method"] = p.getActionArgWithDefaultValues(act, "method")
p.rules = append(p.rules, rule{Action: ActionSetMethod, Part: in, Args: args})
p.rules = append(p.rules, rule{Action: ActionSetMethod, Part: in, Args: args, Once: &sync.Once{}})
return nil
}

View File

@ -20,7 +20,9 @@ func (p *Page) routingRuleHandler(ctx *rod.Hijack) {
switch rule.Action {
case ActionSetMethod:
ctx.Request.Req().Method = rule.Args["method"]
rule.Do(func() {
ctx.Request.Req().Method = rule.Args["method"]
})
case ActionAddHeader:
ctx.Request.Req().Header.Add(rule.Args["key"], rule.Args["value"])
case ActionSetHeader: