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-redirectsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `popsicle-redirects` into a `popsicle` client to automatically follow HTTP redirects, including basic error handling.
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.
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.
Always initialize `redirects` with a valid transport middleware, e.g., `redirects(transport())` when used with `popsicle`.
To enable following 307/308 redirects, provide a custom `confirmRedirect` function in the options: `redirects(transport(), { confirmRedirect: () => true })` or implement more sophisticated logic.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()))`.
Increase the `maxRedirects` option if more redirects are expected, or investigate the target URL for excessive or cyclic redirects. Example: `redirects(transport(), { maxRedirects: 10 })`.Ensure `redirects` is imported as a named export (`import { redirects } from 'popsicle-redirects';`) and called with the `transport()` function: `request.use(redirects(transport()))`.