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

Bug: Duplicate header "Content-Range" in Response (cannot play html video) #7051

Closed
libersoft-org opened this issue Nov 11, 2023 · 2 comments · Fixed by #7199
Closed

Bug: Duplicate header "Content-Range" in Response (cannot play html video) #7051

libersoft-org opened this issue Nov 11, 2023 · 2 comments · Fixed by #7199
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API good first issue Something that would be good for new contributors

Comments

@libersoft-org
Copy link

libersoft-org commented Nov 11, 2023

What version of Bun is running?

1.0.11

What platform is your computer?

Linux 6.1.0-13-amd64 x86_64 unknown (Debain 12)

What steps can reproduce the bug?

const chunk = 1048576; // 1 MB
let [start = 0, end = Infinity] = req.headers.range.split('=').at(-1).split('-').map(Number);
if (end == 0) end = start + chunk < file.size ? start + chunk - 1 : file.size - 1;
const file = Bun.file('big_video.mp4');
return new Response(file.slice(start, start + chunk), {
 status: 206,
 headers: { 'Content-Range': 'bytes ' + start + '-' + end + '/' + file.size }
});

What is the expected behavior?

To have a single header "Content-Range" in response.

What do you see instead?

Two "Content-Range" headers in response.

Additional information

This is because bun does not know the file size, so it creates "Content-Range" ending "/*" instead of "/file_size". So it ends up like this in response:

content-range: bytes 30269309-31317884/1063300891
content-range: bytes 30269309-31317884/*

... two headers "content-range" instead of just one that I set in response.

This is quite a problem when playing a video in "video" html element, because it doesn't know the size of the video, so I have to wait when the whole file is downloaded. Considering video files can have 1 GB+, this is a problem.

Firefox is OK with those two headers and plays the video well, but Chrome does not.

@libersoft-org libersoft-org added the bug Something isn't working label Nov 11, 2023
@libersoft-org libersoft-org changed the title Bug: Duplicate header "Content-Range" in Response Bug: Duplicate header "Content-Range" in Response (cannot play html video) Nov 11, 2023
@Electroid Electroid added bun.js Something to do with a Bun-specific API good first issue Something that would be good for new contributors labels Nov 13, 2023
@TomasHubelbauer
Copy link

@libersoft-org Thank you for including the video streaming sample code. I was looking for something exactly like this and came across this issue while googling around. You've saved me a bunch of time.

@libersoft-org
Copy link
Author

@libersoft-org Thank you for including the video streaming sample code. I was looking for something exactly like this and came across this issue while googling around. You've saved me a bunch of time.

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API good first issue Something that would be good for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants