Call to localhost on another port is always ignored (not proxied) #62

paulcitarella opened this Issue Sep 11, 2012 · 8 comments

2 participants


Scenario: Two grails apps. App A running on port 8081 contains a Spock/Betamax test. App B running on port 8080 provides a REST interface called by the code in app A under test. If app A calls app B with http://localhost:8080, a Betamax tape is not created regardless of the ignoreLocalhost and ignoreHosts settings. Betamax debug logging just shows the proxy starting up and then shutting down after the test - no proxying. If app A calls app B with, everything works as expected. The call is proxied and a tape is created.


Hmm, that's very odd. What are you using to make the connection? It sounds like different routing rules are being applied depending on the target host.


I'm using the grails REST plugin (v0.7) as follows:

def response = withRest(uri: "http://localhost:8080/appB/") {
get(requestContentType: "application/json", path: "thing/1")

The REST plugin is setting the routing policy with:

builder.client.routePlanner = new ProxySelectorRoutePlanner(

@robfletcher robfletcher was assigned Sep 27, 2012

I wonder if this is related to #41? Since both endpoints are on localhost Betamax will try to intercept both the 2nd "inside" the 1st.

@robfletcher robfletcher pushed a commit that referenced this issue Sep 27, 2012
Rob Fletcher failing test for #62 d0b9ed0

Wow, I think this is actually as simple as traffic on localhost never getting proxied. Can't imagine how I missed this throughout all the tests. I've recreated the problem and if I use InetAddress.localHost.hostAddress instead of localhost in the target URL then Betamax proxies correctly.

I will do some investigation & see if there is anything I can do about this.

@robfletcher robfletcher pushed a commit that referenced this issue Sep 28, 2012
Rob Fletcher much simpler test for #62 - still failing 47969ee

Thanks! So sounds like the workaround is to just use an actual IP instead of localhost or I'll give that a try.


Yup. Using my actual IP works as expected. Here's some further testing I did. What's interesting is that an /etc/hosts mapping of any other name than "localhost" to works.

localhost = NO = NO = YES -> = YES
localblah -> = YES


I came across this Oracle bug report which suggests that it should work in Java 7. This is borne out by the fact I pushed the failing test but the Travis build passed (Travis runs with Java 7). I'll check this on my laptop this evening where I also have Java 7 installed.

@robfletcher robfletcher pushed a commit that referenced this issue Sep 28, 2012
Rob Fletcher added bug ref and documentation note for #62 3e926e0

Proxying localhost or does work on Java 7 so I'm going to go ahead and close this issue. There's a viable workaround under Java 6 which is to either use the hostname or non-loopback IP address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment