Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
paulcitarella opened this Issue · 8 comments

2 participants

@paulcitarella

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 http://some_host_mapping.com:8080, everything works as expected. The call is proxied and a tape is created.

@robfletcher
Owner

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.

@paulcitarella

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(
builder.client.connectionManager.schemeRegistry,
ProxySelector.default
)

@robfletcher robfletcher was assigned
@robfletcher
Owner

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 referenced this issue from a commit
Rob Fletcher failing test for #62 d0b9ed0
@robfletcher
Owner

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 referenced this issue from a commit
Rob Fletcher much simpler test for #62 - still failing 47969ee
@paulcitarella

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

@paulcitarella

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 127.0.0.1 works.

localhost = NO
127.0.0.1 = NO
10.176.201.113 = YES
localblah.com -> 127.0.0.1 = YES
localblah -> 127.0.0.1 = YES

@robfletcher
Owner

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 referenced this issue from a commit
Rob Fletcher added bug ref and documentation note for #62 3e926e0
@robfletcher
Owner

Proxying localhost or 127.0.0.1 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
Something went wrong with that request. Please try again.