Language Configuration
Some language-specific environment configuration may be necessary but you should not need to modify your application code to use proxymock.
If you want the full language-specific first-success path, start here:
- Java — Java demo app
- Kotlin — Kotlin demo app
- .NET — .NET demo app
- Node.js — Node.js demo app
- Go — Go demo app
- Python — Python demo app
- Ruby — Ruby demo app
- PHP — PHP demo app
- Rust — Rust demo app
- C++ — C++ demo app
Configuring the Proxy
As the name implies, proxymock is a proxy which works by routing traffic from your application through proxymock before it goes to the final destination.
Proxy support depends on the client library. Some clients ignore environment variables or require explicit proxy settings. Check your client configuration and confirm that a request appears in the recording.
Record inbound traffic by setting the --app-port flag and making requests to port 4143 instead of your application's port.
When to use --map
Use --map when your client ignores proxy environment variables or when it is easier to point the client at a different host and port than configure proxy support.
Pick your recording mode like this:
- HTTP, HTTPS, or gRPC clients that honor proxy environment variables: set
HTTP_PROXY,HTTPS_PROXY, andgrpc_proxy - Clients that support SOCKS: set
ALL_PROXY - Clients that ignore proxy environment variables or use raw TCP protocols such as Redis: use
proxymock record --map
Examples on this page follow the casing conventions commonly used by each runtime. Many proxy-aware clients accept uppercase and lowercase variants. The proxymock CLI overview shows proxy variables, and the proxymock CLI reference covers flags and syntax.
--map tells proxymock to listen on a local port and forward traffic to the real backend. Then point your application at the mapped port instead of the real service.
For example, to record Redis traffic, start proxymock with a port mapping and point your app at that mapped port:
proxymock record --out ./proxymock --map 56379=127.0.0.1:6379
export REDIS_ADDR=127.0.0.1:56379
./my-app
If the backend protocol matters, you can also include it explicitly:
proxymock record --map 65432=postgres://localhost:5432
proxymock record --map 1443=https://httpbin.org:443
For more examples, see the Redis mocking guide, MongoDB guide, MySQL guide, PostgreSQL guide, SQL Server guide, Oracle guide, and Kafka guide.
- Go
- Java
- Kotlin
- Python
- Node.js
- Ruby
- PHP
- C#/.NET
- Rust
Go respects proxy environment variables.
export HTTP_PROXY=http://localhost:4140
export HTTPS_PROXY=http://localhost:4140
export NO_PROXY=localhost,127.0.0.1
Use the SOCKS proxy to capture database traffic:
export ALL_PROXY=socks5://localhost:4140
For a JVM started by proxymock, HTTP/HTTPS proxy and truststore properties are supplied automatically:
proxymock record -- java -jar app.jar
Set JAVA_HOME to your JDK so proxymock can create the truststore if needed. For a separate JVM or IDE, configure http.proxyHost, http.proxyPort, https.proxyHost, and https.proxyPort, plus the Java truststore. Standard Java networking does not use HTTP_PROXY or SOCKS_PROXY as a substitute for these properties.
For a SOCKS-capable TCP client, use -DsocksProxyHost=localhost -DsocksProxyPort=4140. Driver and transport support varies; use --map when the client ignores proxy settings.
See Java with proxymock for complete HTTP, SOCKS, database, IDE, and CI examples. See Java TLS trust for certificate setup.
Kotlin/JVM uses the Java networking stack. Standard JVM HTTP clients ignore HTTP_PROXY and HTTPS_PROXY, so use JVM proxy properties or the SOCKS proxy plus a JKS truststore. See the Kotlin language page for the complete setup.
Python respects proxy environment variables.
export HTTP_PROXY=http://localhost:4140
export HTTPS_PROXY=http://localhost:4140
export NO_PROXY=localhost,127.0.0.1
Use the SOCKS proxy to capture database traffic (requires PySocks package):
export ALL_PROXY=socks5://localhost:4140
Node.js HTTP libraries handle proxies differently. Environment variables are NOT automatically used by most libraries.
On Node 24 (or 22.21+) the recommended path for proxymock is the built-in proxy support — set NODE_USE_ENV_PROXY=1 so the runtime honors HTTP_PROXY/HTTPS_PROXY, and NODE_EXTRA_CA_CERTS to trust the proxymock certificate:
export NODE_USE_ENV_PROXY=1
export HTTP_PROXY=http://localhost:4140
export HTTPS_PROXY=http://localhost:4140
export NODE_EXTRA_CA_CERTS=$HOME/.speedscale/certs/tls.crt
On older Node versions, configure the proxy at the client level.
For axios (requires explicit configuration or https-proxy-agent):
const axios = require('axios');
// Option 1: Direct configuration
axios.get('https://example.com', {
proxy: {
protocol: 'http',
host: 'localhost',
port: 4140
}
});
// Option 2: Using https-proxy-agent
const HttpsProxyAgent = require('https-proxy-agent');
const agent = new HttpsProxyAgent('http://localhost:4140');
axios.get('https://example.com', {
httpsAgent: agent
});
To respect environment variables with axios:
export HTTP_PROXY=http://localhost:4140
export HTTPS_PROXY=http://localhost:4140
Then use a library like https-proxy-agent to read them.
Use the SOCKS proxy to capture database traffic (requires socks-proxy-agent):
const SocksProxyAgent = require('socks-proxy-agent');
const agent = new SocksProxyAgent('socks5://localhost:4140');
Ruby's Net::HTTP honors the http_proxy/https_proxy environment variables by default, so setting them is usually all that is needed:
export http_proxy=http://localhost:4140
export https_proxy=http://localhost:4140
export no_proxy=localhost,127.0.0.1
If you need to opt in explicitly (for example, when the defaults have been overridden), pass :ENV to Net::HTTP:
require 'net/http'
# This will use environment variables
Net::HTTP.new('example.com', nil, :ENV).start do |http|
# Uses proxy from env vars if set
end
# Or with URI
uri = URI('https://example.com')
Net::HTTP.start(uri.host, uri.port, :p_addr => :ENV) do |http|
# Uses proxy from env vars if set
end
PHP proxy behavior depends on the client and build. Configure the proxy explicitly when the client does not honor environment variables. See the PHP language page for a complete record, mock, and replay workflow.
Using cURL:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://example.com");
curl_setopt($ch, CURLOPT_PROXY, "http://localhost:4140");
if ($ca = getenv('SSL_CERT_FILE')) {
curl_setopt($ch, CURLOPT_CAINFO, $ca);
}
// For SOCKS proxy
// curl_setopt($ch, CURLOPT_PROXY, "socks5://localhost:4140");
// With authentication
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "username:password");
$response = curl_exec($ch);
curl_close($ch);
Using stream context:
$context = stream_context_create([
'http' => [
'proxy' => 'tcp://localhost:4140',
'request_fulluri' => true,
],
'ssl' => array_filter([
'cafile' => getenv('SSL_CERT_FILE'),
]),
]);
$response = file_get_contents('https://example.com', false, $context);
Set default proxy for all stream operations:
stream_context_set_default([
'http' => ['proxy' => 'tcp://localhost:4140']
]);
.NET Core/5+ respects proxy environment variables:
export HTTP_PROXY=http://localhost:4140
export HTTPS_PROXY=http://localhost:4140
export NO_PROXY=localhost,127.0.0.1
Rust with the reqwest crate respects proxy environment variables by default:
export HTTP_PROXY=http://localhost:4140
export HTTPS_PROXY=http://localhost:4140
export NO_PROXY=localhost,127.0.0.1
Certificate handling depends on the selected TLS backend. Add the certificate at SSL_CERT_FILE to the client's root certificate store. See the Rust language page for a complete record, mock, and replay workflow.
Use the SOCKS proxy to capture database traffic (requires socks feature in Cargo.toml):
export ALL_PROXY=socks5://localhost:4140
Then modify Cargo.toml to:
reqwest = { version = "your_version_here", features = ["socks"] }
Decrypting TLS
proxymock attempts to automatically configure TLS on the desktop so manual configuration is only necessary in special environments like CI/CD or when TLS decryption does not work out of the box.
Configure TLS trust in the environment that runs your HTTPS client. Clients that use the Windows certificate store need the Windows certificate store steps below.
- Go
- Node.js
- Ruby
- .NET
- Java
- Kotlin
- PHP
- Rust
- C++
- Python
export SSL_CERT_FILE="${HOME}/.speedscale/certs/tls.crt"
Go reads the SSL_CERT_FILE environment variable on Linux to locate trusted root certificates. This environment variable will be automatically populated by the Speedscale operator. Go 1.27 and later also reads it on macOS and Windows. Earlier versions use the keychain on macOS and the Windows certificate store on Windows.
export NODE_EXTRA_CA_CERTS="${HOME}/.speedscale/certs/tls.crt"
For Node.js applications newer than v7.3.0.
export SSL_CERT_FILE="${HOME}/.speedscale/certs/tls.crt"
Ruby applications using OpenSSL will respect the SSL_CERT_FILE environment variable to locate trusted root certificates. This environment variable will be automatically populated by the Speedscale operator.
export SSL_CERT_FILE="${HOME}/.speedscale/certs/tls.crt"
.NET uses OpenSSL on Linux, which respects SSL_CERT_FILE. The default Microsoft .NET Docker base images are Linux based, so this setting applies. On macOS, .NET uses the system keychain, where proxymock adds its CA by default. On Windows, .NET uses the Windows certificate store.
Java uses a truststore. The desktop and Kubernetes paths differ:
- Desktop or CI: create
$HOME/.speedscale/certs/cacerts.jkswithproxymock admin certs --jks, withJAVA_HOMEset. A JVM launched directly byproxymock record -- java ...receives the truststore properties automatically. - Kubernetes sidecar: enable
tls-outandsidecar.speedscale.com/tls-java-tool-options: "true". The operator configures Java to use/etc/ssl/speedscale/jks/cacerts.jksinside the container. - Java-agent capture: keep the application's existing trust configuration. A later replay with mocked TLS dependencies requires trusting the responder CA.
See Java TLS trust for complete commands, custom corporate CAs, replay, and troubleshooting. Truststore settings do not route traffic; configure Java proxy settings when using a forward proxy.
Kotlin/JVM applications use the same JKS truststore and JVM properties as Java. See Kotlin TLS trust for the Kotlin workflow and Java TLS trust for the full truststore reference.
export SSL_CERT_FILE="${HOME}/.speedscale/certs/tls.crt"
PHP cURL does not consistently read SSL_CERT_FILE. Pass it to cURL as CURLOPT_CAINFO; the PHP language page includes the complete example.
export SSL_CERT_FILE="${HOME}/.speedscale/certs/tls.crt"
Rust certificate handling depends on the HTTP client and TLS backend. Add this certificate to the client's root certificate store. The Rust language page describes the rustls and OpenSSL paths.
export SSL_CERT_FILE="${HOME}/.speedscale/certs/tls.crt"
C++ applications using OpenSSL will respect the SSL_CERT_FILE environment variable to locate trusted root certificates. This environment variable will be automatically populated by the Speedscale operator.
export REQUESTS_CA_BUNDLE="${HOME}/.speedscale/certs/tls.crt"
Python applications (including the popular requests library and many others) will use the REQUESTS_CA_BUNDLE environment variable to locate trusted root certificates.
Windows certificate store
Native Windows clients that validate certificates with the Windows certificate store ignore SSL_CERT_FILE. These include .NET, SQL Server drivers, Go before 1.27, Rust with native-tls, and the curl.exe that ships with Windows. Trust the proxymock CA in the Windows certificate store instead. Node.js, Python requests, and Java keep their own trust settings, described in the tabs above.
On a Windows desktop, proxymock init offers to add the CA to your user's Trusted Root Certification Authorities store. Confirm the Windows Security Warning dialog and no further setup is needed. Use the steps below if you declined the dialog, passed --no-cert-install, set up a headless machine, or need trust for another account or the whole machine.
Apply trust to the runtime that opens the HTTPS connection. If the test calls your app and your app calls the dependency, configure trust for your app's account or Windows environment.
-
Locate the public CA,
tls.crt, from the proxymock instance serving the mock. The default Windows path is%USERPROFILE%\.speedscale\certs\tls.crt. Runproxymock admin certsif you need to generate the CA. Share only the public certificate with your endpoint administrator and keeptls.keyon the mock host. -
Choose the trust store approved by your endpoint administrator. For machine-level trust, have them deploy the CA to Local Computer > Trusted Root Certification Authorities. For an approved manual install, run the following from elevated PowerShell with the actual path to the public certificate.
certutil.exe -addstore Root "C:\path\to\tls.crt"For per-user trust, run this from regular PowerShell as the user running the HTTPS client. It does not need administrator rights. Windows shows a confirmation dialog, so it fails in headless sessions. For unattended jobs, have your administrator provision trust for the account or environment where the client runs.
certutil.exe -user -addstore Root "$env:USERPROFILE\.speedscale\certs\tls.crt" -
To verify mocking, start proxymock with your recording and disable passthrough. The example assumes proxymock and the client are running on the same Windows host.
proxymock mock --in .\proxymock\recorded-<timestamp> --out .\proxymock\mock-results --no-passthroughReplace
recorded-<timestamp>with the directoryproxymock recordcreated. Route the client through proxymock in the session that launches it. For clients that read proxy environment variables, setHTTPS_PROXY, using the configured proxy address if you changed the default listener. The language pages cover clients that need other proxy settings, such as .NET Framework.$env:HTTPS_PROXY = "http://127.0.0.1:4140"Run a request that exercises the mocked dependency with TLS validation enabled. Confirm the expected response and check the mock output for
match=HITand zero passthrough. An unmatched request returns HTTP 404. -
When the trust is no longer needed, have the certificate owner remove the CA from the trust store by its exact thumbprint.
certutil.exe -dump "C:\path\to\tls.crt"prints the thumbprint asCert Hash(sha1). For the machine store, run this from elevated PowerShell:certutil.exe -delstore Root <thumbprint>For the per-user store, run this from regular PowerShell as that user:
certutil.exe -user -delstore Root <thumbprint>
See Microsoft's Windows certificate store guide and certutil reference.