Skip to content

Commit

Permalink
fix: correct content-length value
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed May 27, 2024
1 parent 3c578f6 commit 715205a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-waves-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kitajs/fastify-html-plugin': patch
---

Correct content-length value
11 changes: 4 additions & 7 deletions packages/fastify-html-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const kAutoDoctype = Symbol.for('fastify-kita-html.autoDoctype');
* >}
*/
function plugin(fastify, opts, next) {
fastify.decorateReply(kAutoDoctype, (opts.autoDoctype ??= true));
fastify.decorateReply(kAutoDoctype, opts.autoDoctype ?? true);
fastify.decorateReply('html', html);
return next();
}
Expand Down Expand Up @@ -63,12 +63,9 @@ function handleHtml(htmlStr, reply) {
const requestData = SUSPENSE_ROOT.requests.get(reply.request.id);

if (requestData === undefined) {
return (
reply
// Should be safe to use .length instead of Buffer.byteLength here
.header('content-length', handleHtml.length)
.send(htmlStr)
);
return reply
.header('content-length', Buffer.byteLength(htmlStr, 'utf-8'))
.send(htmlStr);
}

requestData.stream.push(htmlStr);
Expand Down

0 comments on commit 715205a

Please sign in to comment.