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

HTTP/2 not following redirects #2836

Closed
kylsgl opened this issue Feb 25, 2024 · 5 comments · Fixed by #3025
Closed

HTTP/2 not following redirects #2836

kylsgl opened this issue Feb 25, 2024 · 5 comments · Fixed by #3025
Labels
bug Something isn't working H2 Pull requests or issues related to HTTP/2

Comments

@kylsgl
Copy link

kylsgl commented Feb 25, 2024

Reproducible By

Using an Agent dispatcher with allowH2 set to true and maxRedirections set to >0

Logs & Screenshots

Response header of https://imgur.com/qRKTc1U.jpeg with maxRedirections set to 50

{
  'retry-after': '0',
  location: 'https://i.imgur.com/qRKTc1U.jpeg',
  'accept-ranges': 'bytes',
  date: 'Sun, 25 Feb 2024 08:55:46 GMT',       
  'x-served-by': 'cache-mrs10565-MRS',
  'x-cache': 'HIT',
  'x-cache-hits': '0',
  'x-timer': 'S1708851346.142524,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',
  'content-length': '0',
  [Symbol(nodejs.http2.sensitiveHeaders)]: []
}

Environment

Node.js v20.11.0
undici 6.6.2

@kylsgl kylsgl added the bug Something isn't working label Feb 25, 2024
@metcoder95
Copy link
Member

We have not tested extensively with redirections so this issue might be overlooked.
Can you provide an
Minimum Reproducible Example to test this out?

@kylsgl
Copy link
Author

kylsgl commented Feb 25, 2024

https://replit.com/@kylsgl4/undici2836

const undici = require("undici");

const origin = "https://imgur.com";

const path = "/qRKTc1U.jpeg";

const agent = new undici.Agent({
  allowH2: true,
});

agent
  .request({
    origin,
    path,
    maxRedirections: 10,
    method: "GET",
  })
  .then(({ statusCode, headers }) => {
    console.log(statusCode, "\n", headers);
  });

@metcoder95 metcoder95 added the H2 Pull requests or issues related to HTTP/2 label Mar 8, 2024
@metcoder95
Copy link
Member

Sadly I couldn't reproduce it; the redirection took place as expected

200
 {
  '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': 'nKbcqHDVlaSbVvxqTL6_Dwsn_EBKGtpp-s5BFSxHCoJCMQ1Bad0EAQ==',
  'cache-control': 'public, max-age=31536000',
  'accept-ranges': 'bytes',
  date: 'Sun, 31 Mar 2024 11:44:12 GMT',
  age: '17008',
  'x-served-by': 'cache-iad-kcgs7200020-IAD, cache-ams12777-AMS',
  'x-cache': 'Miss from cloudfront, HIT, MISS',
  'x-cache-hits': '2, 0',
  'x-timer': 'S1711885453.789978,VS0,VE92',
  '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',
  'content-length': '451104'
}

with maxRedirections: 0

301
 {
  'retry-after': '0',
  location: 'https://i.imgur.com/qRKTc1U.jpeg',
  'accept-ranges': 'bytes',
  date: 'Sun, 31 Mar 2024 11:51:29 GMT',
  'x-served-by': 'cache-ams21075-AMS',
  'x-cache': 'HIT',
  'x-cache-hits': '0',
  'x-timer': 'S1711885889.371931,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',
  'content-length': '0'
}

@kylsgl
Copy link
Author

kylsgl commented Apr 1, 2024

Any ideas what I might be doing wrong? Both my replit (undici@6.6.2) and codesandbox (undici@6.10.2) setups are giving me a 301.

https://replit.com/@kylsgl4/undici2836

https://codesandbox.io/p/devbox/undici-2836-dzc98k?file=%2Findex.js%3A13%2C12

@metcoder95
Copy link
Member

Ok, I see the issue now and why I couldn't reproduce it; I was on branch #3025. This fix solves an issue when passing the headers down to onHeaders hook, currently, it passes an object, but after the fix, it should pass a common array of buffers.

Reopening the issue, and should be solved with #3025, sorry for the confusion

@metcoder95 metcoder95 reopened this Apr 1, 2024
@metcoder95 metcoder95 linked a pull request Apr 1, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working H2 Pull requests or issues related to HTTP/2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants