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
- .NET — .NET demo app
- Node.js — Node.js demo app
- Go — Go demo app
- Python — Python demo app
- Ruby — Ruby 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. The CLI reference uses lowercase shell examples, and many proxy-aware clients accept uppercase and lowercase variants.
--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 MongoDB guide, MySQL guide, PostgreSQL guide, and Kafka guide.
- Go
- Java
- 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.
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 does not automatically use environment variables so it must be set explicitly. There multiple ways to configure proxies depending on the method used.
Using cURL:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://example.com");
curl_setopt($ch, CURLOPT_PROXY, "http://localhost:4140");
// 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' => [
'verify_peer' => false, // Only for testing
]
]);
$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
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.
Commands and flags should be run in the environment where your application is running.
- Go
- Node.js
- Ruby
- .NET
- Java
- C++
- Python
export SSL_CERT_FILE="${HOME}/.speedscale/certs/tls.crt"
Go 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 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 Core uses OpenSSL on Linux and Mac which respects default settings. The default Microsoft .NET Docker base images are Linux based which means these settings apply, however running Windows based workloads may require additional configuration.
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.
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.