Skip to content

Commit

Permalink
#66 set proxy host based on address Netty reports it is using
Browse files Browse the repository at this point in the history
  • Loading branch information
robfletcher committed Aug 5, 2013
1 parent 31b9e4a commit 17e51a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.junit.runners.model.Statement
import static TapeMode.READ_WRITE
import static co.freeside.betamax.MatchRule.*
import static java.util.Collections.EMPTY_MAP
import static java.util.logging.Level.SEVERE
/**
* This is the main interface to the Betamax proxy. It allows control of Betamax configuration and inserting and
* ejecting `Tape` instances. The class can also be used as a _JUnit @Rule_ allowing tests annotated with `@Betamax` to
Expand Down Expand Up @@ -148,6 +149,8 @@ class Recorder implements TestRule {
try {
start(tapeName, arguments)
closure()
} catch (Exception e) {
log.log SEVERE, "Caught exception starting Betamax", e
} finally {
stop()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public InetSocketAddress run() throws Exception {
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true);

channel = bootstrap.bind(port).sync().channel();
channel = bootstrap.bind("localhost", port).sync().channel();
return (InetSocketAddress) channel.localAddress();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ProxyServer implements HttpInterceptor {
address = proxyServer.run()
running = true

overrideProxySettings()
overrideProxySettings address
overrideSSLSettings()
}

Expand Down Expand Up @@ -95,13 +95,12 @@ class ProxyServer implements HttpInterceptor {
httpClient
}

private void overrideProxySettings() {
def proxyHost = InetAddress.localHost.hostAddress
private void overrideProxySettings(InetSocketAddress address) {
def nonProxyHosts = recorder.ignoreHosts as Set
if (recorder.ignoreLocalhost) {
nonProxyHosts.addAll(Network.localAddresses)
}
proxyOverrider.activate proxyHost, port, nonProxyHosts
proxyOverrider.activate address.hostName, address.port, nonProxyHosts
}

private void restoreOriginalProxySettings() {
Expand Down

0 comments on commit 17e51a2

Please sign in to comment.