diff --git a/proxychain/proxychain.go b/proxychain/proxychain.go index 0b36224..506f06a 100644 --- a/proxychain/proxychain.go +++ b/proxychain/proxychain.go @@ -83,16 +83,17 @@ proxychain.NewProxyChain(). └─────────┘ └────────────────────────┘ └─────────┘ */ type ProxyChain struct { - Context *fiber.Ctx - Client *http.Client - Request *http.Request - Response *http.Response - requestModifications []RequestModification - resultModifications []ResponseModification - htmlTokenRewriters []rr.IHTMLTokenRewriter - Ruleset *ruleset.RuleSet - debugMode bool - abortErr error + Context *fiber.Ctx + Client *http.Client + Request *http.Request + Response *http.Response + requestModifications []RequestModification + onceRequestModifications []RequestModification + resultModifications []ResponseModification + htmlTokenRewriters []rr.IHTMLTokenRewriter + Ruleset *ruleset.RuleSet + debugMode bool + abortErr error } // a ProxyStrategy is a pre-built proxychain with purpose-built defaults @@ -113,13 +114,20 @@ func (chain *ProxyChain) SetRequestModifications(mods ...RequestModification) *P return chain } -// AddRequestModifications sets the ProxyChain's request modifers +// AddRequestModifications adds more request modifers to the ProxyChain // the modifier will not fire until ProxyChain.Execute() is run. func (chain *ProxyChain) AddRequestModifications(mods ...RequestModification) *ProxyChain { chain.requestModifications = append(chain.requestModifications, mods...) return chain } +// AddOnceRequestModification adds a request modifier to the ProxyChain that should only fire once +// the modifier will not fire until ProxyChain.Execute() is run and will be removed after it has been applied. +func (chain *ProxyChain) AddOnceRequestModification(mod ...RequestModification) *ProxyChain { + chain.onceRequestModifications = append(chain.onceRequestModifications, mod...) + return chain +} + // AddResponseModifications sets the ProxyChain's response modifers // the modifier will not fire until ProxyChain.Execute() is run. func (chain *ProxyChain) AddResponseModifications(mods ...ResponseModification) *ProxyChain { @@ -357,6 +365,15 @@ func (chain *ProxyChain) _execute() (io.Reader, error) { } } + // Apply onceRequestModifications to proxychain and clear them + for _, applyOnceRequestModificationsTo := range chain.onceRequestModifications { + err := applyOnceRequestModificationsTo(chain) + if err != nil { + return nil, chain.abort(err) + } + } + chain.onceRequestModifications = nil + // Send Request Upstream resp, err := chain.Client.Do(chain.Request) if err != nil {