Steve Teplica
03/28/2023, 4:58 PM-Dhttp.proxyHost=localhost
-Dhttp.proxyPort=1080
-Dhttp.nonProxyHosts=
I am starting a local WireMock server with http port 1080. The spring application is definitely routing requests through the designated proxy, but my WireMock server is not forwarding these requests to their destination.
My goal is to have WireMock return stubs if there is a mapping match, otherwise forward the request to its destination and log the forwarded request.
Is WireMock able to act as a proxy server in this way?
I am using wiremock-jre8-standalone
2.35.0. The WireMock Proxy docs mentions a WireMockServer option passThroughProxy(Boolean)
(which it says defaults to “true”), which sounds exactly like what I want. But I don’t see this option available on this version of WireMock.Tom
03/28/2023, 7:21 PM.enableBrowserProxying(true)
in the Java startup options, or --enable-browser-proxying
from the CLI.Steve Teplica
03/30/2023, 3:43 PM-Dhttps.proxyHost=localhost
-Dhttps.proxyPort=1083
-Dhttps.nonProxyHosts=
Changes to WireMock Server:
• I configured WireMock’s HTTPS port to 1083
• I added a ConsoleNotifyingWiremockNetworkTrafficListener
to log info on incoming/outgoing network traffic.
• These are the current relevent WireMock configurations:
WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.options()
.port(1080)
.httpsPort(1083)
.enableBrowserProxying(true)
.trustAllProxyTargets(true)
.preserveHostHeader(true)
...
)
Observed behavior:
• It looks like the initial HTTP CONNECT request (to open a tunnel to client’s request destination) is closing prematurely or failing:
2023-03-29 16:25:53.924 Opened Socket[addr=/127.0.0.1,port=53213,localport=1083]
2023-03-29 16:25:53.930 Incoming bytes: CONNECT <http://subdomain.domain.com:443|subdomain.domain.com:443> HTTP/1.1
Host: <http://subdomain.domain.com:443|subdomain.domain.com:443>
Proxy-Connection: Keep-Alive
User-Agent: okhttp/3.8.1
2023-03-29 16:25:53.938 Outgoing bytes: P
2023-03-29 16:25:53.943 Closed Socket[unconnected]
@Tom Do you have any advice for debugging this further? Or does this appear as an obvious symptom, to you, of something being misconfigured? Any help is greatly appreciated 😄<http://subdomain.domain.com|subdomain.domain.com>
. This is an endpoint that can only be reached while on my corporate network (I’m VPN’d in). The spring application normally sends these requests directly to that endpoint. The spring application does have a keystore and a truststore. I’m not sure if/how those should be used from WireMockTom
03/31/2023, 10:00 AMSteve Teplica
04/03/2023, 4:24 PMhttp.proxyPort
and https.proxyPort
to the same port. So I did the same thing for my spring app, and then everything was working!