Proxy Lifecycle

Create, list, and destroy proxy sessions. Each session runs on its own port.

POST /proxy

Create a new proxy session. Returns the port number of the new proxy listener. Optionally request a specific port.

Request Parameters (form-encoded or query)

ParameterTypeDescription
portintegerOptional. Request a specific port for the proxy listener.
trustAllServersbooleanOptional. Skip upstream TLS certificate verification.

Response

{
  "port": 8081
}

Example

# Create proxy on auto-assigned port
curl -X POST http://localhost:8080/proxy

# Create proxy on specific port
curl -X POST http://localhost:8080/proxy?port=9091
GET /proxy

List all active proxy sessions and their ports.

Response

{
  "proxyList": [
    { "port": 8081 },
    { "port": 8082 }
  ]
}

Example

curl http://localhost:8080/proxy
DELETE /proxy/{port}

Shut down a proxy session and release its port. Any in-progress HAR data is discarded.

Path Parameters

ParameterTypeDescription
portintegerThe port of the proxy session to delete.

Example

curl -X DELETE http://localhost:8080/proxy/8081

HAR Capture

Start, retrieve, and manage HTTP Archive (HAR 1.2) capture for proxy sessions.

PUT /proxy/{port}/har

Start or reset HAR capture for the given proxy session. If HAR capture is already active, this resets and returns the previous HAR data.

Request Parameters (form-encoded or query)

ParameterTypeDescription
initialPageRefstringOptional. Name of the initial page ref. Defaults to "Page 1".
initialPageTitlestringOptional. Title of the initial page.
captureHeadersbooleanOptional. Capture request/response headers. Default: false.
captureContentbooleanOptional. Capture response body content. Default: false.
captureBinaryContentbooleanOptional. Capture binary response bodies as base64. Default: false.

Response

Returns the previous HAR data if capture was already active, otherwise empty.

Example

# Start HAR capture with headers and content
curl -X PUT "http://localhost:8080/proxy/8081/har?captureHeaders=true&captureContent=true"
GET /proxy/{port}/har

Retrieve the current HAR data for the proxy session. Returns a complete HAR 1.2 JSON document.

Response

{
  "log": {
    "version": "1.2",
    "creator": { "name": "har-capture-proxy", "version": "0.1.0" },
    "pages": [...],
    "entries": [...]
  }
}

Example

# Retrieve HAR and save to file
curl http://localhost:8080/proxy/8081/har -o capture.har
PUT /proxy/{port}/har/pageRef

Start a new page within the current HAR capture. Subsequent entries are associated with the new page ref.

Request Parameters (form-encoded or query)

ParameterTypeDescription
pageRefstringName of the new page ref.
pageTitlestringOptional. Title of the new page.

Example

curl -X PUT "http://localhost:8080/proxy/8081/har/pageRef?pageRef=checkout&pageTitle=Checkout+Page"

Headers & Auth

Add custom headers or basic authentication to proxied requests.

POST /proxy/{port}/headers

Set additional headers that will be sent with every request through this proxy session.

Request Body (JSON)

{
  "X-Custom-Header": "my-value",
  "Authorization": "Bearer token123"
}

Example

curl -X POST http://localhost:8080/proxy/8081/headers \
  -H "Content-Type: application/json" \
  -d '{"X-Custom-Header": "my-value"}'
POST /proxy/{port}/auth/basic/{domain}

Set basic authentication credentials for a specific domain. The proxy will automatically add the Authorization header for matching requests.

Path Parameters

ParameterTypeDescription
domainstringThe domain to authenticate to (e.g., "example.com").

Request Body (JSON)

{
  "username": "admin",
  "password": "secret"
}

Example

curl -X POST http://localhost:8080/proxy/8081/auth/basic/example.com \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": "secret"}'

URL Filtering

Control which URLs the proxy allows or blocks using regex patterns.

PUT /proxy/{port}/whitelist

Set a whitelist of URL patterns. Requests not matching any pattern receive the specified HTTP status code.

Request Parameters (form-encoded)

ParameterTypeDescription
regexstringComma-separated list of regex patterns to whitelist.
statusintegerHTTP status code to return for non-matching requests (e.g., 404).

Example

curl -X PUT http://localhost:8080/proxy/8081/whitelist \
  -d "regex=.*\.example\.com.*,.*\.cdn\.com.*&status=404"
DELETE /proxy/{port}/whitelist

Clear the whitelist, allowing all requests through.

Example

curl -X DELETE http://localhost:8080/proxy/8081/whitelist
PUT /proxy/{port}/blacklist

Add a URL pattern to the blacklist. Matching requests receive the specified HTTP status code.

Request Parameters (form-encoded)

ParameterTypeDescription
regexstringRegex pattern to blacklist.
statusintegerHTTP status code to return for matching requests (e.g., 403).

Example

curl -X PUT http://localhost:8080/proxy/8081/blacklist \
  -d "regex=.*\.tracking\.com.*&status=403"

Network Configuration

Bandwidth throttling, latency, timeouts, host mapping, DNS, retries, and URL rewriting.

PUT /proxy/{port}/limit

Set bandwidth limits and latency for the proxy session. Useful for simulating slow network conditions.

Request Parameters (form-encoded)

ParameterTypeDescription
downstreamKbpsintegerDownstream bandwidth limit in Kbps.
upstreamKbpsintegerUpstream bandwidth limit in Kbps.
latencyintegerAdded latency in milliseconds.
enablebooleanEnable or disable bandwidth limiting. Default: true.
payloadPercentageintegerPercentage of data to consider as payload. Default: 100.
maxBitsPerSecondintegerAlternative: max bits per second (downstream).

Example

# Simulate 3G network
curl -X PUT http://localhost:8080/proxy/8081/limit \
  -d "downstreamKbps=384&upstreamKbps=128&latency=200"
PUT /proxy/{port}/timeout

Set connection and request timeouts for the proxy session.

Request Parameters (form-encoded or JSON)

ParameterTypeDescription
requestTimeoutintegerRequest timeout in milliseconds.
readTimeoutintegerRead timeout in milliseconds.
connectionTimeoutintegerConnection timeout in milliseconds.
dnsCacheTimeoutintegerDNS cache TTL in seconds.

Example

curl -X PUT http://localhost:8080/proxy/8081/timeout \
  -d "requestTimeout=30000&connectionTimeout=5000"
POST /proxy/{port}/hosts

Map hostnames to IP addresses, overriding DNS resolution for the proxy session.

Request Body (JSON)

{
  "example.com": "127.0.0.1",
  "api.example.com": "10.0.0.5"
}

Example

curl -X POST http://localhost:8080/proxy/8081/hosts \
  -H "Content-Type: application/json" \
  -d '{"example.com": "127.0.0.1"}'
PUT /proxy/{port}/retry

Set the number of retry attempts for failed requests.

Request Parameters (form-encoded)

ParameterTypeDescription
retrycountintegerNumber of retry attempts. 0 disables retries.

Example

curl -X PUT http://localhost:8080/proxy/8081/retry \
  -d "retrycount=3"
PUT /proxy/{port}/rewrite

Add URL rewrite rules. Matching URLs are rewritten before the request is forwarded upstream.

Request Body (JSON)

{
  "matchRegex": "http://example\\.com/(.*)",
  "replace": "http://staging.example.com/$1"
}

Example

curl -X PUT http://localhost:8080/proxy/8081/rewrite \
  -H "Content-Type: application/json" \
  -d '{"matchRegex": "http://example\\.com/(.*)", "replace": "http://staging.example.com/$1"}'
DELETE /proxy/{port}/dns/cache

Clear the DNS cache for the proxy session.

Example

curl -X DELETE http://localhost:8080/proxy/8081/dns/cache
PUT /proxy/{port}/wait

Wait for all active requests to complete, up to the specified timeout. Useful for ensuring all traffic is captured before retrieving HAR.

Request Parameters (form-encoded)

ParameterTypeDescription
quietPeriodInMsintegerWait until no new requests have been made for this many milliseconds.
timeoutInMsintegerMaximum time to wait in milliseconds.

Example

curl -X PUT "http://localhost:8080/proxy/8081/wait?quietPeriodInMs=2000&timeoutInMs=30000"

Request & Response Filters

BMP-compatible JavaScript filters for modifying requests and responses.

POST /proxy/{port}/filter/request

Add a JavaScript request filter. The script receives the request object and can modify headers, URL, or body before it is forwarded upstream.

Request Body (text/plain)

A JavaScript function body that receives request and contents parameters.

Example

curl -X POST http://localhost:8080/proxy/8081/filter/request \
  -H "Content-Type: text/plain" \
  -d 'request.headers().add("X-Test", "true");'
POST /proxy/{port}/filter/response

Add a JavaScript response filter. The script receives the response object and can modify headers, status, or body before it is returned to the client.

Request Body (text/plain)

A JavaScript function body that receives response and contents parameters.

Example

curl -X POST http://localhost:8080/proxy/8081/filter/response \
  -H "Content-Type: text/plain" \
  -d 'response.headers().add("X-Proxied", "har-capture-proxy");'

Response Mutation RulesNew

Powerful response mutation rules that go beyond what BrowserMob Proxy offers. Modify JSON, HTML, and text responses on the fly using declarative rules.

POST /proxy/{port}/rules

Add one or more response mutation rules. Rules are matched against responses by URL pattern and applied in order. Supports JSON mutations (JSONPath), HTML transforms (CSS selectors), text replacements, and sandboxed JavaScript transforms.

Request Body (JSON)

An array of rule objects. Each rule has a url_pattern (regex) and one or more mutation types.

JSON Mutation Rule

[
  {
    "url_pattern": ".*api\\.example\\.com/users.*",
    "json_mutations": [
      {
        "selector": "$.data[*].email",
        "action": "set",
        "value": "redacted@example.com"
      },
      {
        "selector": "$.data[*].phone",
        "action": "delete"
      }
    ]
  }
]

HTML Transform Rule

[
  {
    "url_pattern": ".*example\\.com.*",
    "html_transforms": [
      {
        "selector": "h1.title",
        "action": "set_text",
        "value": "Modified Title"
      },
      {
        "selector": "img.logo",
        "action": "set_attribute",
        "attribute": "src",
        "value": "/custom-logo.png"
      }
    ]
  }
]

Text Replacement Rule

[
  {
    "url_pattern": ".*example\\.com.*",
    "text_replacements": [
      {
        "find": "Old Company Name",
        "replace": "New Company Name"
      }
    ]
  }
]

JavaScript Transform Rule

[
  {
    "url_pattern": ".*api\\.example\\.com/data.*",
    "js_transform": "function transform(body) { let data = JSON.parse(body); data.timestamp = Date.now(); return JSON.stringify(data); }"
  }
]

Fake Data Generation Rule

[
  {
    "url_pattern": ".*api\\.example\\.com/users.*",
    "json_mutations": [
      {
        "selector": "$.data[*].name",
        "action": "set",
        "value": "{{fake.name}}"
      },
      {
        "selector": "$.data[*].email",
        "action": "set",
        "value": "{{fake.email}}"
      }
    ]
  }
]

curl Examples

# Add a JSON mutation rule
curl -X POST http://localhost:8080/proxy/8081/rules \
  -H "Content-Type: application/json" \
  -d '[{"url_pattern": ".*api\\.example\\.com.*", "json_mutations": [{"selector": "$.name", "action": "set", "value": "Test User"}]}]'

# Add an HTML transform rule
curl -X POST http://localhost:8080/proxy/8081/rules \
  -H "Content-Type: application/json" \
  -d '[{"url_pattern": ".*example\\.com.*", "html_transforms": [{"selector": "title", "action": "set_text", "value": "Custom Title"}]}]'

# Add a text replacement rule
curl -X POST http://localhost:8080/proxy/8081/rules \
  -H "Content-Type: application/json" \
  -d '[{"url_pattern": ".*", "text_replacements": [{"find": "foo", "replace": "bar"}]}]'
GET /proxy/{port}/rules

Retrieve all currently active response mutation rules for the proxy session.

Response

[
  {
    "url_pattern": ".*api\\.example\\.com.*",
    "json_mutations": [
      {
        "selector": "$.name",
        "action": "set",
        "value": "Test User"
      }
    ]
  }
]

Example

curl http://localhost:8080/proxy/8081/rules
DELETE /proxy/{port}/rules

Remove all response mutation rules from the proxy session.

Example

curl -X DELETE http://localhost:8080/proxy/8081/rules