awslabs / llrt

LLRT (Low Latency Runtime) is an experimental, lightweight JavaScript runtime designed to address the growing demand for fast and efficient Serverless applications.
Apache License 2.0
7.73k stars 342 forks source link

Redirects are not handled in fetch() #340

Closed nabetti1720 closed 2 months ago

nabetti1720 commented 2 months ago

In other implementations (node, bun, etc.), when fetching the specified URI, a redirect is processed and the final response (status code 200) is returned, but in llrt, the redirect is not processed and status code 301 is returned.

Reproduction procedure:

// fetch.js
const main = async () => {
  try {
    const response = await fetch('https://google.com');
    console.log(response.status);
    console.log(response.headers.get('location'));
  } catch(e) {
    console.log(e);
  }
}

main();

Execution results in llrt:

shinya@MBA2022M2 llrt-test % ./llrt fetch.js 
301
https://www.google.com/

Execution results in bun:

shinya@MBA2022M2 llrt-test % bun fetch.js 
200
null
richarddavison commented 2 months ago

Thanks for the well documented report. PR is welcome, want to take shot at it? This could be implemented as looping over the response until no redirect header is present if redirect option is set to follow on the Request or fetch options. https://github.com/awslabs/llrt/blob/d05da26103acc1fdf45afe15965ef05013e5f488/src/http/fetch.rs#L81

nabetti1720 commented 2 months ago

Hi @richarddavison , I would love to work on this assignment if the opportunity arises :)