Documentation Index
Fetch the complete documentation index at: https://mintlify.com/binary-person/rammerhead/llms.txt
Use this file to discover all available pages before exploring further.
RammerheadProxy extends testcafe-hammerhead’s Proxy class and is the central component of every Rammerhead deployment. It handles HTTP and WebSocket routing, manages request and upgrade pipelines, rewrites server response headers, and integrates with a session store. You create exactly one instance per process and pair it with a session store via attachToProxy.
You should not call
openSession() directly on RammerheadProxy. Use a session store class (such as RammerheadSessionFileCache or RammerheadSessionMemoryStore) and call attachToProxy instead.Constructor
start() call.
Logger instance used for request traffic and internal debug messages. Defaults to a silent logger.
Function that extracts the client IP address from an incoming request. Override this when Rammerhead runs behind a reverse proxy that forwards the real IP in a header such as
X-Forwarded-For.Hostname or IP address the HTTP server binds to.
Port for the primary proxy server to listen on.
Port used to simulate cross-origin requests. Sites that inspect the
Origin header require this. Set to null to disable cross-domain simulation and run a single server port, but be aware that some sites will break.When
true, the HTTP server is created but listen() is never called. Use this when integrating with a sticky-session cluster library that manages binding externally.TLS/SSL options passed directly to Node’s
https.createServer. Set to null to use plain HTTP. Provide an object with key and cert (or pfx) to enable HTTPS.Function that returns the server info object hammerhead uses when rewriting URLs. The default implementation reads
req.headers.host and detects TLS from the socket. Override this in a reverse-proxy setup where the public hostname, port, or protocol differ from what Node sees.When
true, the /syncLocalStorage route returns 404 and localStorage data is never persisted to the session. Useful if you do not need cross-device localStorage sync and want to reduce server load.Cache instance used to store rewritten JavaScript. Defaults to a 50 MB in-memory LRU cache. Swap in
RammerheadJSFileCache for disk-backed caching that survives restarts and can be shared across cluster workers.When
true, all sessions created by this proxy disable HTTP/2 on their outgoing connections. This is set globally via global.rhDisableHttp2 so it applies to every RammerheadSession created after the proxy starts.Properties
rewriteServerHeaders
undefined removes the header; returning a string replaces it.
The default transformers:
| Header | Effect |
|---|---|
permissions-policy | Replaces sync-xhr with sync-yes so synchronous XHR is not blocked |
feature-policy | Same replacement as permissions-policy |
referrer-policy | Always set to no-referrer-when-downgrade |
report-to | Removed (avoids leaking proxy endpoint to report collectors) |
cross-origin-embedder-policy | Removed (allows embedding cross-origin resources) |
Methods
GET
URL path to match, e.g.
'/my-endpoint'.Either a static content object
{ content: Buffer, contentType: string } or a request handler function.POST
URL path to match.
Either a static content object or a request handler function.
WS
WebSocket connection to your handler.
Path or pattern to match. String routes use exact matching;
RegExp routes use .test().Called once the WebSocket handshake completes.
ws is the client connection.Options forwarded to
new WebSocket.Server(...). noServer: true is always applied automatically.The underlying
ws server instance for the route.unregisterWS
The same route value passed to
WS().getWSRoute
URL path to look up.
When
true, the matched route is removed from the registry after being returned.The route descriptor, or
null if no match is found.addToOnRequestPipeline
_onRequest). Return true from a handler to stop processing and prevent the request from reaching hammerhead.
Handler function. Receives:
req—http.IncomingMessageres—http.ServerResponse(orstream.Duplexfor WebSocket upgrades)serverInfo—ServerInfocomputed bygetServerInfoisRoute—trueif the path matches a registered GET/POST/WS routeisWebsocket—trueif the request is a WebSocket upgrade
When
true, the handler is prepended to the pipeline so it runs before existing handlers. When false (default), it is appended.addToOnUpgradePipeline
head buffer during a WebSocket upgrade, since hammerhead does not forward it through _onRequest.
Handler function. Receives:
req—http.IncomingMessagesocket—stream.Duplexhead—Bufferwith any data received after the upgrade headersserverInfo—ServerInfoisRoute—trueif the path matches a registered route
Same prepend/append semantics as
addToOnRequestPipeline.checkIsRoute
true if the request matches any registered GET, POST, or WS route.
When passed an
IncomingMessage, matches against HTTP routes and WebSocket routes by URL path. When passed a RegExp, checks WebSocket routes only.true if any matching route is found.close
Proxy.close() and then proxy.openSessions.close().