#serveStatic Content-Length not included

1 messages · Page 1 of 1 (latest)

thick geyser
#

I've this code:

app.use(
  "/files/*",
  serveStatic({
    root: resolve(`/app/public`),
    rewriteRequestPath: (path) => {
      return path.replace(/^\/files/, "");
    },
  }),
);

For some reason, when I download any of those .zip files it'll not show the total size.

After some research I found that there is NO Content-Length + Transfer-Encoding is set to chunked.

This works fine but I need, yes need, not want, the Content-Length as I need to add a download progress bar and this do not allow me to.

How can we fix this? I've been trying a lot of things but anything seems to work.

marble wedge
#

can you give more context like is this hono? and does it work how you want in node?

thick geyser
#

Of course. I have 2 projects that are basically the same but one is newer.

Old API

  • Node + NPM to manage packages
  • Bun installed through NPM
  • Hono as web server
  • I run the app with bun
    On this project the code I sent you works fine
    https://github.com/XurxoMF/vs-launcher-api on the src/index.ts file
    It's using bun 1.2.22 I think

Test

If I run curl -v -o /dev/null http://localhost:3000/files/versions/windows/1.22.0-rc.8.zip 2>&1 | head -100 I can see this headers:

< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Content-Type: application/zip
< content-disposition: filename="1.22.0-rc.8.zip"
< content-length: 637849401
< Date: Sun, 12 Apr 2026 12:38:20 GMT

New API

  • Bun to manage packages
  • Bun installed globally
  • Hono as web server
  • I run the app with bun
    On this project it doesn't work
    https://github.com/XurxoMF/rustory-api on the src/index.ts file
    It's using the latest version on both my computer and docker oven/bun image

Test

If I run curl -v -o /dev/null http://localhost:3000/files/versions/windows/1.22.0-rc.8.zip 2>&1 | head -100 I can see this headers:

* Request completely sent off
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Content-Type: application/zip
< Date: Sun, 12 Apr 2026 12:37:22 GMT
< Transfer-Encoding: chunked
#

It should be doing the same as they both have the same exact code (at least on the serverStatic part, I changed some other small things)

#

The only difference is the bun version and in one of them I use the oven/bun docker image and on the other I use the node image

#

I'm not sure if this error is caused by Hono, Bun, docker image... it makes no sense at all

#

I first thought it was a Traefik/Cloudflare issue but it does the same locally inside the containers where the APIs are running so it's not that. It's something internal

#

Also thought about file permissions on the server not allowing my API to check the size but they have the same permissions too

thick geyser
#

serveStatic Content-Length not included

marble wedge
thick geyser
#

Usually it is the other way xD

#

I'll open an issue then

#

Thank you so much ❤️

marble wedge
#

oh damn

thick geyser
#

I found an issue reporting something similar but I think it's the same thing so...
On the issue they report missing content-length header behind nginx but I'm behing traefik.
Reading the comments it looks like it's not nginx but something with bun and http 1.0/1.1 so I suppose it'll be that