-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Origin/proxy v2 #50
Draft
deoxykev
wants to merge
194
commits into
main
Choose a base branch
from
origin/proxy_v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Origin/proxy v2 #50
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…and proxified URLs; direct injection from golang
…ers; improve html rewriter edge case handling
# Aider chat conversation: USER: Modify proxychain.go such that there is a public API to add a RequestModification to fire only once. ASSISTANT: To make this change we need to modify `proxychain/proxychain.go` to: 1. Add a new field `onceRequestModifications` in the `ProxyChain` struct to store the request modifications that should only fire once. 2. Add a new method `AddOnceRequestModification` to add a request modification that should only fire once. 3. Update the `_execute` method to apply the `onceRequestModifications` and clear them after they have been applied. Here are the *SEARCH/REPLACE* blocks: proxychain/proxychain.go <source> <<<<<<< SEARCH 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 } ======= type ProxyChain struct { 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 } >>>>>>> REPLACE </source> proxychain/proxychain.go <source> <<<<<<< SEARCH // AddRequestModifications sets the ProxyChain's request modifers // 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 } ======= // 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 } >>>>>>> REPLACE </source> proxychain/proxychain.go <source> <<<<<<< SEARCH // _execute sends the request for the ProxyChain and returns the raw body only // the caller is responsible for returning a response back to the requestor // the caller is also responsible for calling chain._reset() when they are done with the body func (chain *ProxyChain) _execute() (io.Reader, error) { if chain.validateCtxIsSet() != nil || chain.abortErr != nil { return nil, chain.abortErr } if chain.Request == nil { return nil, errors.New("proxychain request not yet initialized") } if chain.Request.URL.Scheme == "" { return nil, errors.New("request url not set or invalid. Check ProxyChain ReqMods for issues") } // Apply requestModifications to proxychain for _, applyRequestModificationsTo := range chain.requestModifications { err := applyRequestModificationsTo(chain) if err != nil { return nil, chain.abort(err) } } ======= // _execute sends the request for the ProxyChain and returns the raw body only // the caller is responsible for returning a response back to the requestor // the caller is also responsible for calling chain._reset() when they are done with the body func (chain *ProxyChain) _execute() (io.Reader, error) { if chain.validateCtxIsSet() != nil || chain.abortErr != nil { return nil, chain.abortErr } if chain.Request == nil { return nil, errors.New("proxychain request not yet initialized") } if chain.Request.URL.Scheme == "" { return nil, errors.New("request url not set or invalid. Check ProxyChain ReqMods for issues") } // Apply requestModifications to proxychain for _, applyRequestModificationsTo := range chain.requestModifications { err := applyRequestModificationsTo(chain) if err != nil { return nil, chain.abort(err) } } // 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 >>>>>>> REPLACE </source>
# Aider chat conversation: USER: Modify proxychain.go such that there is a public API to add a ResponseModification to fire only once. ASSISTANT: To make this change we need to modify `proxychain/proxychain.go` to: 1. Add a new field `onceResultModifications` in the `ProxyChain` struct to store the response modifications that should only fire once. 2. Add a new method `AddOnceResponseModification` to add a response modification that should only fire once. 3. Update the `_execute` method to apply the `onceResultModifications` and clear them after they have been applied. Here are the *SEARCH/REPLACE* blocks: proxychain/proxychain.go <source> <<<<<<< SEARCH onceRequestModifications []RequestModification resultModifications []ResponseModification ======= onceRequestModifications []RequestModification onceResultModifications []ResponseModification resultModifications []ResponseModification >>>>>>> REPLACE </source> proxychain/proxychain.go <source> <<<<<<< SEARCH // 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 } ======= // 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 } // AddOnceResponseModification adds a response 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) AddOnceResponseModification(mod ...ResponseModification) *ProxyChain { chain.onceResultModifications = append(chain.onceResultModifications, mod...) return chain } >>>>>>> REPLACE </source> proxychain/proxychain.go <source> <<<<<<< SEARCH // 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 ======= // Apply onceRequestModifications and onceResultModifications to proxychain and clear them for _, applyOnceRequestModificationsTo := range chain.onceRequestModifications { err := applyOnceRequestModificationsTo(chain) if err != nil { return nil, chain.abort(err) } } chain.onceRequestModifications = nil for _, applyOnceResultModificationsTo := range chain.onceResultModifications { err := applyOnceResultModificationsTo(chain) if err != nil { return nil, chain.abort(err) } } chain.onceResultModifications = nil >>>>>>> REPLACE </source>
feat: Playground
Render error page when accept header is text/html
…into origin/proxy_v2
…are not applied on a single proxychain pass
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIP
Improvements
Usage
Todo:
New Request Modifiers
New Response Modifiers