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

Etag middleware generating the same weak etag for different body content. #3536

Closed
markusahlstrand opened this issue Oct 21, 2024 · 1 comment · Fixed by #3604
Closed

Etag middleware generating the same weak etag for different body content. #3536

markusahlstrand opened this issue Oct 21, 2024 · 1 comment · Fixed by #3604
Labels

Comments

@markusahlstrand
Copy link

What version of Hono are you using?

4.6.5

What runtime/platform is your app running on?

Cloudflare workers

What steps can reproduce the bug?

Generate a large response (20kb) with the etag middleware using weak etags, change a character in the response again.

What is the expected behavior?

When changing the response body the etag should be different

What do you see instead?

Different response bodies generate the same etag

Additional information

When output'ing the respons body used for generating the hash it looks like this:

body ReadableStream {
  locked: false
}

This is the section in the middleware that we had a look at:

  const hash = await sha1(res.clone().body || '')
      etag = weak ? `W/"${hash}"` : `"${hash}"`

I'm guessing that hono starts to stream the body at some size of response body which breaks the etag functionality. I'm not sure what the best fix is in this case. Is it possible to disable the streaming or to read the entire stream into a string at this point?

@usualoma
Copy link
Member

Hi @markusahlstrand

Thank you for your report. This is a known issue and is currently stuck, but there is a pull request.

#2911
#2918

I would like to fix it with one of these, so please wait a little.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants