Skip to content
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

Implement Hoverfly configuration by PAC file #766

Merged
merged 12 commits into from
Aug 23, 2018
Merged

Implement Hoverfly configuration by PAC file #766

merged 12 commits into from
Aug 23, 2018

Conversation

benjih
Copy link
Contributor

@benjih benjih commented Aug 23, 2018

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.

function FindProxyForURL(url, host) {
	// our local URLs from the domains below example.com don't need a proxy:
	if (shExpMatch(host, "*.example.com"))
	{
		return "DIRECT";
	}

	// URLs within this network are accessed through
	// port 8080 on fastproxy.example.com:
	if (isInNet(host, "10.0.0.0", "255.255.248.0"))
	{
		return "PROXY fastproxy.example.com:8080";
	}

	// All other requests go through port 8080 of proxy.example.com.
	// should that fail to respond, go directly to the WWW:
	return "PROXY proxy.example.com:8080; DIRECT";
}

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.

@benjih
Copy link
Contributor Author

benjih commented Aug 23, 2018

Forgot to mention, as I needed to pull new dependency in, things obviously went sideways, hence all the vendor changes.

@benjih benjih closed this Aug 23, 2018
@benjih benjih reopened this Aug 23, 2018
@benjih benjih merged commit 88ec7f6 into master Aug 23, 2018
@benjih benjih deleted the pac branch August 23, 2018 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants