Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client not following redirects #3184

Closed
kylsgl opened this issue May 1, 2024 · 1 comment
Closed

Client not following redirects #3184

kylsgl opened this issue May 1, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@kylsgl
Copy link

kylsgl commented May 1, 2024

Bug Description

Client not following redirects

Reproducible By

const undici = require("undici");

const dispatcherOpts = {
  maxRedirections: 1,
};

const requestOpts = {
  method: "GET",
  origin: "https://imgur.com",
  path: "/qRKTc1U.jpeg",
};

new undici.Agent(dispatcherOpts)
  .request(requestOpts)
  .then(({ statusCode, headers }) => {
    console.log("Agent:", statusCode, "\n", headers);
  })
  .catch(console.error);

new undici.Client(requestOpts.origin, dispatcherOpts)
  .request(requestOpts)
  .then(({ statusCode, headers }) => {
    console.log("Client:", statusCode, "\n", headers);
  })
  .catch(console.error);

Expected Behavior

It should follow the redirect

Logs & Screenshots

Agent: 200 
 {
  connection: 'keep-alive',
  'content-length': '451104',
  'content-type': 'image/jpeg',
  'last-modified': 'Mon, 22 May 2023 13:33:03 GMT',
  etag: '"bf7cfe5aa4341b0761cab33d795c539f"',      
  'x-amz-storage-class': 'STANDARD_IA',
  'x-amz-server-side-encryption': 'AES256',
  'x-amz-cf-pop': 'IAD12-P2',
  'x-amz-cf-id': '0PT3Lf5C_pPRg_IyvPvm_mYlrK_DDZH7QayqRmKuzJndkgH_nhrXVg==',
  'cache-control': 'public, max-age=31536000',
  'accept-ranges': 'bytes',
  age: '54681',
  date: 'Wed, 01 May 2024 11:30:03 GMT',
  'x-served-by': 'cache-iad-kcgs7200020-IAD, cache-bur-kbur8200095-BUR',
  'x-cache': 'Miss from cloudfront, HIT, HIT',
  'x-cache-hits': '2, 0',
  'x-timer': 'S1714563003.252339,VS0,VE1',
  'strict-transport-security': 'max-age=300',
  'access-control-allow-methods': 'GET, OPTIONS',
  'access-control-allow-origin': '*',
  server: 'cat factory 1.0',
  'x-content-type-options': 'nosniff'
}

Client: 301 
 {
  connection: 'close',
  'content-length': '0',
  'retry-after': '0',
  location: 'https://i.imgur.com/qRKTc1U.jpeg',
  'accept-ranges': 'bytes',
  date: 'Wed, 01 May 2024 11:30:04 GMT',
  'x-served-by': 'cache-fra-eddf8230146-FRA',
  'x-cache': 'HIT',
  'x-cache-hits': '0',
  'x-timer': 'S1714563005.568657,VS0,VE0',
  server: 'cat factory 1.0',
  'strict-transport-security': 'max-age=300',
  'cache-control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
  'x-frame-options': 'DENY',
  'access-control-allow-origin': 'https://imgur.com',
  'access-control-allow-credentials': 'false'
}

Environment

undici@6.15.0
Node.js v22.0.0

@kylsgl kylsgl added the bug Something isn't working label May 1, 2024
@mcollina
Copy link
Member

mcollina commented May 1, 2024

It can't. The Client can only talk to 1 origin, so it can't follow redirects.

You can add single host redirects with https://github.com/nodejs/undici/blob/main/docs/docs/api/Dispatcher.md#example-1---basic-compose

@mcollina mcollina closed this as not planned Won't fix, can't repro, duplicate, stale May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants