gornostay25 / svelte-adapter-bun

A SvelteKit adapter for Bun
MIT License
534 stars 33 forks source link

[Bug] HTTP Range requests send 1 byte less than requested #65

Open jakmeier opened 2 months ago

jakmeier commented 2 months ago

Hi!

TLDR: I found a bug and here is the fix: https://github.com/gornostay25/svelte-adapter-bun/pull/64

Context:

I noticed that loading videos using a HTML5 <video> tag didn't work when I hosted my application through svelte-adapter-bun.

After a while, I figured out that all 206 partial content responses had one byte less than expected. This ended in a infinite-loop of 1-byte requests that got a 0-byte response back.

For example, this request:

GET /video/example.mp4 HTTP/1.1
Range: bytes=5742303-

I would get back

HTTP/1.1 206 Partial Content
Content-Type: video/mp4
Content-Length: 0
Content-Range: bytes 5742303-5742303/5742304
Accept-Ranges: bytes

...after which my browser just sends the same request again and again.

Eventually, I found the bug in svelte-adapter-bun, which creates a slice of a file using the inclusive end definition for a slice constructor that expects an exclusive definition. A classic off-by-one error :)

@gornostay25 Please take a look at my PR #64 to fix that.

ckiee commented 1 month ago

Hi! Just wanted to say thanks, I also just hit this (: