Registry / http-networking / popsicle-redirects

popsicle-redirects

JSON →
library1.1.1jsnpmunverified

Popsicle Redirects is a middleware package for the Popsicle HTTP client library, designed to automatically follow HTTP redirects (e.g., 301, 302, 307, 308). It abstracts away the complexity of handling redirect chains, allowing developers to configure the maximum number of redirects and define custom confirmation logic for non-idempotent redirects (307/308). The current stable version is 1.1.1. The project appears to follow an as-needed release cadence for bug fixes and minor improvements, typically tied to the `servie` ecosystem. Its primary differentiator is its integration into the `popsicle` middleware pattern, providing a specific solution for redirect handling within that client.

npm install popsicle-redirects
INSTALL
IMPORT
SIG · POPSICLE-REDIRECTS
P
popsicle-redirects
http-networkingjavascriptv1.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

redirects
import { redirects } from 'popsicle-redirects';
const { redirects } = require('popsicle-redirects');
The library primarily promotes ESM usage. While CommonJS `require` might work with transpilation or specific Node.js configurations, direct `import` is the idiomatic way.
redirects (default import)
import { redirects } from 'popsicle-redirects';
import redirects from 'popsicle-redirects';
The `redirects` function is a named export, not a default export. Attempting a default import will result in `undefined`.
Middleware Integration
import { redirects } from 'popsicle-redirects'; import { transport } from 'popsicle'; const redirectMiddleware = redirects(transport()); // Add redirectMiddleware to your Popsicle request chain
import { redirects } from 'popsicle-redirects'; const redirectMiddleware = redirects();
The `redirects` function expects a 'throwback' compatible middleware function as an argument, typically the `transport()` function from `popsicle` itself, or another middleware capable of handling the initial request.

This quickstart demonstrates how to integrate `popsicle-redirects` into a `popsicle` client to automatically follow HTTP redirects, including basic error handling.

import { request } from 'popsicle'; import { redirects } from 'popsicle-redirects'; import { transport } from 'popsicle'; async function fetchDataWithRedirects() { const httpClient = request .use(redirects(transport())) // Integrate the redirects middleware .use(async (request, next) => { // Example of custom middleware or error handling try { const response = await next(request); if (!response.ok) { console.error(`HTTP Error: ${response.status} ${response.statusText}`); } return response; } catch (error) { console.error('Request failed:', error.message); throw error; } }); try { const response = await httpClient.get('http://example.com/redirect-to-target'); const data = await response.text(); console.log('Response data:', data); } catch (error) { console.error('Failed to fetch:', error.message); } } fetchDataWithRedirects();
Debug
Known issues
breakingWhen upgrading to v1.1.1, ensure your application does not rely on cookies being forwarded during cross-origin redirects. This version introduced a security fix that discards cookies when redirected away to a different origin, preventing potential information leakage.
fix
Review existing code for assumptions about cookie forwarding during redirects. If cookie forwarding is explicitly required for specific same-origin scenarios after a redirect, consider implementing custom logic or ensuring redirects remain within the same origin.
affects: >=1.1.1
gotchaPrevious versions (prior to v1.0.1) could enter an infinite redirect loop if a malformed or cyclic redirect chain was encountered due to a flaw in request cloning.
fix
Upgrade to `popsicle-redirects@1.0.1` or later to resolve the infinite redirect loop issue. Always ensure your redirect chain eventually terminates or configure a `maxRedirects` option to prevent excessive loops.
affects: <1.0.1
gotchaThe `redirects` function expects a 'throwback' compatible middleware, typically `popsicle`'s `transport()` function. Passing nothing or an incompatible middleware will result in runtime errors.
fix
Always initialize `redirects` with a valid transport middleware, e.g., `redirects(transport())` when used with `popsicle`.
affects: >=1.0.0
gotchaBy default, 307 (Temporary Redirect) and 308 (Permanent Redirect) status codes, which typically preserve the request method, are not automatically followed unless explicitly confirmed. The default `confirmRedirect` option returns `false`.
fix
To enable following 307/308 redirects, provide a custom `confirmRedirect` function in the options: `redirects(transport(), { confirmRedirect: () => true })` or implement more sophisticated logic.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'use')
Attempting to use `redirects` without providing a valid middleware function, or incorrectly chaining it with `popsicle.request`.
fix
Ensure `redirects` is called with a compatible middleware, typically `transport()` from `popsicle`, and then correctly chained in the `request.use()` call: `request.use(redirects(transport()))`.
Error: Too many redirects
The HTTP request encountered more redirects than the configured `maxRedirects` limit (default is 5).
fix
Increase the `maxRedirects` option if more redirects are expected, or investigate the target URL for excessive or cyclic redirects. Example: `redirects(transport(), { maxRedirects: 10 })`.
TS2345: Argument of type 'typeof import("...")' is not assignable to parameter of type 'Middleware'.
Incorrectly importing or using the `redirects` function as a default import, or attempting to pass `redirects` directly where a middleware is expected without calling it.
fix
Ensure `redirects` is imported as a named export (`import { redirects } from 'popsicle-redirects';`) and called with the `transport()` function: `request.use(redirects(transport()))`.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
servierequiredPeer dependency, likely required for the underlying middleware functionality (though `popsicle` uses `servie` internally, `popsicle-redirects` might directly expose `servie`-compatible interfaces or rely on its types/utilities).
Agent activity
4 hits · last 30 days
node
4
Resources