Implement Hoverfly configuration by PAC file #766
Merged
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.
I have added a new endpoint to Hoverfly called
/v2/api/hoverfly/pac
. A user can GET or PUT a PAC file from/to this endpoint. Putting a PAC file on this endpoint will allow Hoverfly to dynamically set the upstream proxy based on the result of the PAC file. This should fulfill issue #762 and older issue #583.PAC files are Javascript functions that are usually executed by a client like a web browser.
I have achieved this by using jackwakefield/gopac, which uses github.com/robertkrimen/otto, A Javascript interpreter written in Golang. If a PAC file is provided, it will get parsed and executed in by the interpreter and then with the result, will configure a HTTP client correctly.
There are functional tests in this PR proving Hoverfly retrieving responses from two different Hoverfly instances running in simulate mode, with the routing between the two instances determined by a PAC file.