or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication.mderror-handling.mdhttp-client.mdindex.mdnetwork-transport.mdobservability.mdpipeline.mdrequest-processing.mdretry-policies.mdutilities.md
tile.json

network-transport.mddocs/

Network and Transport

Network-level policies for proxy configuration, TLS settings, HTTP agent management, and redirect handling, primarily for Node.js environments.

Capabilities

Proxy Policy

Configures proxy settings for outgoing requests in Node.js environments.

/**
 * A policy that configures proxy settings for outgoing requests (Node.js only)
 * @param proxySettings - Proxy configuration options
 * @returns PipelinePolicy that handles proxy configuration
 */
function proxyPolicy(proxySettings?: ProxySettings): PipelinePolicy;

/**
 * Gets the default proxy settings from environment variables
 * @returns ProxySettings from environment or undefined
 */
function getDefaultProxySettings(): ProxySettings | undefined;

/**
 * The programmatic identifier of the proxyPolicy
 */
const proxyPolicyName: string;

interface ProxySettings {
  /**
   * The proxy's host address. Must include the protocol (e.g., http:// or https://)
   */
  host: string;

  /**
   * The proxy host's port
   */
  port: number;

  /**
   * The user name to authenticate with the proxy, if required
   */
  username?: string;

  /**
   * The password to authenticate with the proxy, if required
   */
  password?: string;
}

Usage Examples:

import { proxyPolicy, getDefaultProxySettings, type ProxySettings } from "@azure/core-rest-pipeline";

// Use environment proxy settings
const envProxy = getDefaultProxySettings();
if (envProxy) {
  pipeline.addPolicy(proxyPolicy(envProxy));
}

// Configure custom proxy
const customProxy: ProxySettings = {
  host: "http://proxy.company.com",
  port: 8080,
  username: "user",
  password: "pass"
};
pipeline.addPolicy(proxyPolicy(customProxy));

Agent Policy

Configures custom HTTP/HTTPS agents for Node.js environments.

/**
 * A policy that configures a custom HTTP agent for requests (Node.js only)
 * @param agent - The HTTP agent to use
 * @returns PipelinePolicy that sets the HTTP agent
 */
function agentPolicy(agent: Agent): PipelinePolicy;

/**
 * The programmatic identifier of the agentPolicy
 */
const agentPolicyName: string;

/**
 * An interface compatible with NodeJS's `http.Agent`
 */
interface Agent {
  /**
   * Destroy any sockets that are currently in use by the agent
   */
  destroy(): void;
  
  /**
   * For agents with keepAlive enabled, this sets the maximum number of sockets that will be left open in the free state
   */
  maxFreeSockets: number;
  
  /**
   * Determines how many concurrent sockets the agent can have open per origin
   */
  maxSockets: number;
  
  /**
   * An object which contains queues of requests that have not yet been assigned to sockets
   */
  requests: unknown;
  
  /**
   * An object which contains arrays of sockets currently in use by the agent
   */
  sockets: unknown;
}

Usage Examples:

import { agentPolicy, type Agent } from "@azure/core-rest-pipeline";
import * as https from "https";

// Custom HTTPS agent with specific configuration
const customAgent = new https.Agent({
  keepAlive: true,
  maxSockets: 10,
  timeout: 30000,
  rejectUnauthorized: true
});

pipeline.addPolicy(agentPolicy(customAgent));

TLS Policy

Configures TLS/SSL settings including certificates and authentication.

/**
 * A policy that configures TLS settings for HTTPS requests (Node.js only)
 * @param tlsSettings - TLS configuration options
 * @returns PipelinePolicy that handles TLS configuration
 */
function tlsPolicy(tlsSettings: TlsSettings): PipelinePolicy;

/**
 * The programmatic identifier of the tlsPolicy
 */
const tlsPolicyName: string;

interface TlsSettings {
  /**
   * Optionally override the trusted CA certificates
   */
  ca?: string | Buffer | Array<string | Buffer> | undefined;
  
  /**
   * Cert chains in PEM format
   */
  cert?: string | Buffer | Array<string | Buffer> | undefined;
  
  /**
   * Private keys in PEM format
   */
  key?: string | Buffer | Array<Buffer | KeyObject> | undefined;
  
  /**
   * Shared passphrase used for a single private key and/or a PFX
   */
  passphrase?: string | undefined;
  
  /**
   * PFX or PKCS12 encoded private key and certificate chain
   */
  pfx?: string | Buffer | Array<string | Buffer | PxfObject> | undefined;
}

interface KeyObject {
  /**
   * Private keys in PEM format
   */
  pem: string | Buffer;
  
  /**
   * Optional passphrase
   */
  passphrase?: string | undefined;
}

interface PxfObject {
  /**
   * PFX or PKCS12 encoded private key and certificate chain
   */
  buf: string | Buffer;
  
  /**
   * Optional passphrase
   */
  passphrase?: string | undefined;
}

Usage Examples:

import { tlsPolicy, type TlsSettings } from "@azure/core-rest-pipeline";
import * as fs from "fs";

// TLS with client certificate
const tlsSettings: TlsSettings = {
  cert: fs.readFileSync("client-cert.pem"),
  key: fs.readFileSync("client-key.pem"),
  ca: fs.readFileSync("ca-cert.pem"),
  passphrase: "certificate-password"
};

pipeline.addPolicy(tlsPolicy(tlsSettings));

Redirect Policy

Handles HTTP redirects with configurable maximum redirect count.

/**
 * A policy that follows HTTP redirects automatically
 * @param options - Options for configuring redirect behavior
 * @returns PipelinePolicy that handles redirects
 */
function redirectPolicy(options?: RedirectPolicyOptions): PipelinePolicy;

/**
 * The programmatic identifier of the redirectPolicy
 */
const redirectPolicyName: string;

interface RedirectPolicyOptions {
  /**
   * The maximum number of redirects to follow. Defaults to 20.
   */
  maxRetries?: number;
}

Usage Examples:

import { redirectPolicy, type RedirectPolicyOptions } from "@azure/core-rest-pipeline";

// Default redirect handling
pipeline.addPolicy(redirectPolicy());

// Custom redirect limits
const redirectOptions: RedirectPolicyOptions = {
  maxRetries: 10
};
pipeline.addPolicy(redirectPolicy(redirectOptions));

Network Policy Configuration

Network policies are typically configured together for comprehensive transport handling:

import { 
  createPipelineFromOptions,
  proxyPolicy,
  agentPolicy,
  tlsPolicy,
  redirectPolicy,
  getDefaultProxySettings
} from "@azure/core-rest-pipeline";
import * as https from "https";
import { isNodeLike } from "@azure/core-util";

const pipeline = createPipelineFromOptions({});

// Node.js specific network configuration
if (isNodeLike) {
  // Custom HTTPS agent
  const agent = new https.Agent({
    keepAlive: true,
    maxSockets: 15
  });
  pipeline.addPolicy(agentPolicy(agent));

  // TLS configuration
  const tlsSettings = {
    rejectUnauthorized: true,
    ca: process.env.CUSTOM_CA_CERT
  };
  if (tlsSettings.ca) {
    pipeline.addPolicy(tlsPolicy(tlsSettings));
  }

  // Proxy configuration
  const proxySettings = getDefaultProxySettings();
  if (proxySettings) {
    pipeline.addPolicy(proxyPolicy(proxySettings));
  }
}

// Redirect handling (works in both Node.js and browser)
pipeline.addPolicy(redirectPolicy({ maxRetries: 15 }));

Policy Names

/**
 * Policy name constants for use in pipeline configuration
 */
const proxyPolicyName: string;
const agentPolicyName: string;
const tlsPolicyName: string;
const redirectPolicyName: string;