Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
paulcitarella opened this Issue · 8 comments

2 participants

Paul Citarella Rob Fletcher
Paul Citarella

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.

Rob Fletcher
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.

Paul Citarella

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
)

Rob Fletcher robfletcher was assigned
Rob Fletcher
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.

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

Rob Fletcher robfletcher referenced this issue from a commit
Rob Fletcher much simpler test for #62 - still failing 47969ee
Paul Citarella

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.

Paul Citarella

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

Rob Fletcher
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.

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