Steve Teplica03/28/2023, 4:58 PM
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
-Dhttp.proxyHost=localhost -Dhttp.proxyPort=1080 -Dhttp.nonProxyHosts=
2.35.0. The WireMock Proxy docs mentions a WireMockServer option
(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.
Tom03/28/2023, 7:21 PM
in the Java startup options, or
from the CLI.
Steve Teplica03/30/2023, 3:43 PM
Changes to WireMock Server: • I configured WireMock’s HTTPS port to 1083 • I added a
-Dhttps.proxyHost=localhost -Dhttps.proxyPort=1083 -Dhttps.nonProxyHosts=
to log info on incoming/outgoing network traffic. • These are the current relevent WireMock configurations:
Observed behavior: • It looks like the initial HTTP CONNECT request (to open a tunnel to client’s request destination) is closing prematurely or failing:
WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.options() .port(1080) .httpsPort(1083) .enableBrowserProxying(true) .trustAllProxyTargets(true) .preserveHostHeader(true) ... )
@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 😄
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]
. 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 WireMock
Tom03/31/2023, 10:00 AM
Steve Teplica04/03/2023, 4:24 PM
to the same port. So I did the same thing for my spring app, and then everything was working!