# Redirect Chain Tracer (`eichan/redirect-chain-tracer`) Actor

- **URL**: https://apify.com/eichan/redirect-chain-tracer.md
- **Developed by:** [Eichan Jolly](https://apify.com/eichan) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$3.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Redirect Chain Tracer

Trace the redirect steps for **one public HTTP(S) URL**. Returns one dataset item containing the sequence of HTTP statuses, Location headers, and time-to-response-headers. Redirects are **only followed on the exact original hostname**, up to the configured hop limit.

### Who it's for

Web developers, site administrators, and QA engineers investigating unexpected redirects, loops, HTTPS upgrades, and redirect limits without visiting pages in a browser.

### Input

```json
{
  "url": "https://example.com/",
  "max_hops": 5
}
```

- `url` (required): exactly one public HTTP(S) URL (maximum 2048 characters).
- `max_hops` (optional, default `5`): how many redirects the Actor can follow, from `1` to `10`. The first response is always inspected, even when the limit is reached.
- No credentials, login, cookies, or nonstandard ports.

### Output (default dataset)

One item per run. The following is an **illustrative** response for a hypothetical same-host redirect; real servers may return a different chain.

```json
{
  "start_url": "http://example.com/old",
  "hops": [
    {
      "url": "http://example.com/old",
      "status_code": 301,
      "location": "/new",
      "response_ms": 82
    },
    {
      "url": "http://example.com/new",
      "status_code": 200,
      "location": null,
      "response_ms": 77
    }
  ],
  "final_url": "http://example.com/new",
  "next_url": null,
  "stop_reason": "complete",
  "error": null
}
```

**`next_url` clarification:** This field is `null` when the trace finishes at a non-redirect response. When a redirect is blocked or exceeds a limit, it holds the absolute proposed destination that **was not fetched**. `final_url` is the last URL for which an HTTP response was received; it is `null` if the first request fails.

`stop_reason` is one of `complete`, `external_redirect`, `insecure_redirect`, `redirect_loop`, `redirect_limit`, `invalid_redirect`, `missing_location`, `request_error`, or `invalid_input`. Transport failures populate `error` with plain language, never a traceback. HTTP `4xx`/`5xx` statuses count as completed HTTP responses rather than exceptions.

### Limits and safety

- Follows up to **10 redirects**, and only if each destination keeps the original hostname (same hostname, case-insensitive; `www.example.com` and `example.com` are different). A cross-host Location is **reported, not requested**.
- HTTPS-to-HTTP downgrades are **reported, not followed**. Same-host HTTP-to-HTTPS upgrades are allowed.
- A redirect to a forbidden scheme, a URL containing credentials, or a nonstandard port is not requested.
- Only response headers are read using `GET`; response bodies are never downloaded. Each request has a 10-second socket timeout; DNS resolver delays are environment-dependent.
- Public IPs only. DNS is checked before connecting, and the checked addresses are used for the connection. No login, browser, JavaScript, retries, or Apify SDK.
- The `Location` header is supplied by the remote server and should be treated as untrusted data by downstream consumers.

### Storage: Apify and local execution

This Actor uses Python's standard library only. On Apify, the platform-provided `APIFY_TOKEN` is used **solely for reading the run's INPUT record and saving its dataset item using the Apify REST API**. The token is never sent to websites or provided as a user input. Cloud storage authorization is required to publish dataset items without an Apify SDK.

For local execution, create `storage/key_value_stores/default/INPUT.json` using the example above, then run:

```sh
python src/main.py
```

The default dataset item is saved under `storage/datasets/default/` as a numbered JSON file. `APIFY_LOCAL_STORAGE_DIR` overrides the local storage root. Local output files do not automatically appear in Apify Console.

### Store classification and pricing suggestion

- **Apify Store category:** `DEVELOPER_TOOLS`.
- **Suggested pricing:** Pay-per-event / **USD $0.003 per trace result**. Exactly one dataset item is produced per run, so one result corresponds to one run. Suggested only: enable and price the default dataset item billing event in Apify Console. `store_metadata.json` records the category and recommendation.

### Deployment

Each folder is an independent Actor with its own `Dockerfile`, `.actor/actor.json`, `input_schema.json`, and source. It needs no third-party Python dependencies. Verify the cloud run and billing setup in Apify Console before publication.

# Actor input Schema

## `url` (type: `string`):

The public HTTP(S) URL to trace, including scheme.

## `max_hops` (type: `integer`):

Maximum number of same-host redirects followed after the first HTTP response.

## Actor input object example

```json
{
  "url": "https://example.com/",
  "max_hops": 5
}
```

# Actor output Schema

## `dataset` (type: `string`):

Dataset containing the Actor's result items

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "url": "https://example.com/"
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/redirect-chain-tracer").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "url": "https://example.com/" }

# Run the Actor and wait for it to finish
run = client.actor("eichan/redirect-chain-tracer").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "url": "https://example.com/"
}' |
apify call eichan/redirect-chain-tracer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eichan/redirect-chain-tracer"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/cOBXbFFQRyojE3Xg0/builds/V3xPYhDGmVUd1fyIu/openapi.json
