Skip to content

Conversation

@tshmieldev
Copy link
Contributor

@tshmieldev tshmieldev commented Dec 6, 2025

This PR fixes honojs/hono#4563
The issue was, lstat does not follow symlinks, so it read the wrong content length and an incomplete file was returned to the client. Changed lstat to stat, and the behavior is as expected (matches what we get when we run the server with bun adapters instead of node-server)

Copilot AI review requested due to automatic review settings December 6, 2025 17:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the static file serving middleware where symbolic links were not handled correctly. The issue was that lstatSync does not follow symlinks, causing it to read metadata from the symlink itself rather than the target file. This resulted in incorrect Content-Length headers and incomplete file responses. The fix changes lstatSync to statSync, which follows symlinks and retrieves the correct file metadata, making the behavior consistent with other runtime adapters like Bun.

  • Changed lstatSync to statSync to properly follow symbolic links when serving static files
  • Updated the import statement to reflect the new function usage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tshmieldev tshmieldev changed the title Fix for hono issue 4563 Fix for hono issue 4563 - incorrect content-length after following symlink Dec 6, 2025
@usualoma
Copy link
Member

usualoma commented Dec 6, 2025

Thank you 👍

@tshmieldev
Copy link
Contributor Author

Please let me know if this looks good or if you’d prefer some adjustments, I'm really happy to help! :)

@yusukebe yusukebe changed the title Fix for hono issue 4563 - incorrect content-length after following symlink fix: Fix for hono issue 4563 - incorrect content-length after following symlink Dec 8, 2025
Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Member

yusukebe commented Dec 8, 2025

@tshmieldev

Nice fix! Thank you very much for your contribution!

@yusukebe yusukebe merged commit 38e17b5 into honojs:main Dec 8, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serveStatic in @hono/node-server serves symlink path instead of resolved file content

3 participants