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

Bun 1.0.3 - fetch does not preserve headers on 303 redirect #6053

Closed
etinquis opened this issue Sep 25, 2023 · 2 comments · Fixed by #6162
Closed

Bun 1.0.3 - fetch does not preserve headers on 303 redirect #6053

etinquis opened this issue Sep 25, 2023 · 2 comments · Fixed by #6162
Labels
bug Something isn't working web-api Something that relates to a standard Web API

Comments

@etinquis
Copy link

etinquis commented Sep 25, 2023

What version of Bun is running?

1.0.3+25e69c71e70ac8a0a88f9cf15b4057bd7b2a633a

What platform is your computer?

Docker Desktop on Windows

What steps can reproduce the bug?

server.ts

import { Serve } from 'bun';

console.log('starting server');

export default {
    port: 80,
    fetch(req: Request) {
        const url = new URL(req.url);

        if(req.method == 'PUT') {
            return new Response(null, {status: 303, headers: { 'Location' : '/redirect'}} );
        }
        const header = req.headers.get('X-Test');
        return new Response(`Redirected ${header}`, {status: 200});
    }
} satisfies Serve;

client.ts

const response = await fetch('http://localhost:80', { verbose: true, method:'PUT', headers:{ 'X-Test': 'TEST'}});
console.trace(response, await response.text());
docker run --rm -v .:/home/bun/app --name bun-server oven/bun:1.0.3 bun run server.ts
docker exec -it bun-server bun run client.ts

What is the expected behavior?

When running with bun 1.0.2:

docker run --rm -v .:/home/bun/app --name bun-server oven/bun:1.0.2 bun run server.ts
docker exec -it bun-server bun run client.ts
Request: PUT /
        x-test: TEST
        Connection: keep-alive
        User-Agent: Bun/1.0.2
        Accept: */*
        Host: localhost
        Accept-Encoding: gzip, deflate
        Content-Length: 0

Response: < 303 See Other
<       Location: /redirect
<       Date: Mon, 25 Sep 2023 20:53:55 GMT
<       Content-Length: 0

Request: GET /redirect
        x-test: TEST
        Connection: keep-alive
        User-Agent: Bun/1.0.2
        Accept: */*
        Host: localhost
        Accept-Encoding: gzip, deflate

Response: < 200 OK
<       content-type: text/plain;charset=utf-8
<       Date: Mon, 25 Sep 2023 20:53:55 GMT
<       Content-Length: 15

Response (0 KB) {
  ok: true,
  url: "http://localhost/redirect",
  headers: Headers {
    "content-type": "text/plain;charset=utf-8",
    "date": "Mon, 25 Sep 2023 20:53:55 GMT",
    "content-length": "15"
  },
  statusText: "OK",
  redirected: true,
  bodyUsed: true,
  status: 200
} Redirected TEST
      at /home/bun/app/client.ts:2:0

What do you see instead?

Request: PUT /
        x-test: TEST
        Connection: keep-alive
        User-Agent: Bun/1.0.3
        Accept: */*
        Host: localhost
        Accept-Encoding: gzip, deflate
        Content-Length: 0

Response: < 303 See Other
<       Location: /redirect
<       Date: Mon, 25 Sep 2023 20:55:25 GMT
<       Content-Length: 0

Request: GET /redirect
        Connection: keep-alive
        User-Agent: Bun/1.0.3
        Accept: */*
        Host: localhost
        Accept-Encoding: gzip, deflate

Response: < 200 OK
<       content-type: text/plain;charset=utf-8
<       Date: Mon, 25 Sep 2023 20:55:25 GMT
<       Content-Length: 15

Response (0 KB) {
  ok: true,
  url: "http://localhost/redirect",
  headers: Headers {
    "content-type": "text/plain;charset=utf-8",
    "date": "Mon, 25 Sep 2023 20:55:25 GMT",
    "content-length": "15"
  },
  statusText: "OK",
  redirected: true,
  bodyUsed: true,
  status: 200
} Redirected null
      at /home/bun/app/client.ts:2:0

X-Test header is not passed to the redirect GET.

Additional information

No response

@etinquis etinquis added the bug Something isn't working label Sep 25, 2023
@Electroid Electroid added the web-api Something that relates to a standard Web API label Sep 25, 2023
@colinhacks
Copy link
Contributor

colinhacks commented Sep 26, 2023

This was changed here to conform more closely to the fetch specification: https://github.com/oven-sh/bun/pull/5729/files

Spec: https://fetch.spec.whatwg.org/#http-redirect-fetch

Screenshot 2023-09-25 at 8 06 36 PM

@etinquis
Copy link
Author

@colinhacks See my comment on whatwg/fetch#1711. By my reading (given that request-body-header name is defined as a subset of headers), this implementation does not comply with the spec.

A request-body-header name is a [header name](https://fetch.spec.whatwg.org/#header-name) that is a [byte-case-insensitive](https://infra.spec.whatwg.org/#byte-case-insensitive) match for one of:

`Content-Encoding`
`Content-Language`
`Content-Location`
`Content-Type`

Jarred-Sumner added a commit that referenced this issue Sep 29, 2023
Jarred-Sumner added a commit that referenced this issue Sep 29, 2023
Fixes #6053

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working web-api Something that relates to a standard Web API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants