or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-6/

Cross-Protocol Redirect Client

Build an HTTP helper that makes requests to a configurable base URL, handles redirects across protocols, and exposes redirect metadata for callers.

Capabilities

Follow cross-protocol redirects

  • Requesting http://service.local/start that responds with a 301 to https://service.local/data yields status 200, body text {"ok":true}, finalUrl https://service.local/data, and records a single redirect entry with 301 and the https location. @test

Manual redirect inspection

  • When manual redirect mode is enabled, a request to a URL that responds with 302 does not follow the redirect; it returns status 302, exposes the Location header value, and records exactly one redirect entry for that hop. @test

Error on disallowed redirects

  • When redirect mode is set to fail, a 307 response causes the operation to reject with redirect-specific error details and no redirect is followed. @test

Respect redirect limits and method normalization

  • With maxRedirects set to 2, a POST request receiving a 303 to https://api.test/form and then a 301 to https://api.test/final completes with a GET to the final URL, drops the original body on the redirected request, and records both redirects in order without exceeding the limit. @test

Implementation

@generates

API

export interface RedirectClientOptions {
  baseUrl?: string;
  maxRedirects?: number;
  mode?: 'auto' | 'manual' | 'fail';
}

export interface RedirectMetadata {
  status: number;
  location: string;
}

export interface RedirectResult {
  status: number;
  finalUrl: string;
  body: any;
  redirects: RedirectMetadata[];
  location?: string;
}

export function buildClient(defaults?: RedirectClientOptions): {
  request(
    path: string,
    options?: RedirectClientOptions & {
      method?: string;
      body?: any;
      headers?: Record<string, string>;
    }
  ): Promise<RedirectResult>;
};

Dependencies { .dependencies }

make-fetch-happen { .dependency }

HTTP client used for redirect handling, including redirect modes, max follow configuration, protocol switch support, and redirect-related errors. @satisfied-by