@@ -263,7 +263,10 @@ export const mapResponse = (
263263 set . headers [ 'content-type' ] = 'text/plain;charset=utf8'
264264
265265 if ( res ) {
266- set . headers [ 'content-length' ] = ( response as string ) . length
266+ set . headers [ 'content-length' ] = Buffer . byteLength (
267+ response as string ,
268+ 'utf8'
269+ )
267270 res . writeHead ( set . status ! , set . headers )
268271 res . end ( response )
269272 }
@@ -275,7 +278,10 @@ export const mapResponse = (
275278 response = JSON . stringify ( response )
276279
277280 set . headers [ 'content-type' ] = 'application/json;charset=utf8'
278- set . headers [ 'content-length' ] = ( response as string ) . length
281+ set . headers [ 'content-length' ] = Buffer . byteLength (
282+ response as string ,
283+ 'utf8'
284+ )
279285
280286 if ( res ) {
281287 res . writeHead ( set . status ! , set . headers )
@@ -349,7 +355,10 @@ export const mapResponse = (
349355 response = JSON . stringify ( response )
350356
351357 set . headers [ 'content-type' ] = 'application/json;charset=utf8'
352- set . headers [ 'content-length' ] = ( response as string ) ?. length
358+ set . headers [ 'content-length' ] = Buffer . byteLength (
359+ response as string ,
360+ 'utf8'
361+ )
353362
354363 if ( res ) {
355364 res . writeHead ( set . status ! , set . headers )
@@ -392,7 +401,10 @@ export const mapResponse = (
392401 response = ( response as number | boolean ) . toString ( )
393402
394403 set . headers [ 'content-type' ] = 'text/plain;charset=utf8'
395- set . headers [ 'content-length' ] = ( response as string ) . length
404+ set . headers [ 'content-length' ] = Buffer . byteLength (
405+ response as string ,
406+ 'utf8'
407+ )
396408
397409 if ( res ) {
398410 res . writeHead ( set . status ! , set . headers )
@@ -477,7 +489,10 @@ export const mapResponse = (
477489 'application/json;charset=utf8'
478490
479491 response = JSON . stringify ( response )
480- set . headers [ 'content-length' ] = ( response as string ) . length
492+ set . headers [ 'content-length' ] = Buffer . byteLength (
493+ response as string ,
494+ 'utf8'
495+ )
481496
482497 if ( res ) {
483498 res . writeHead ( set . status ! , set . headers )
@@ -489,7 +504,10 @@ export const mapResponse = (
489504 }
490505
491506 set . headers [ 'content-type' ] = 'text/plain;charset=utf8'
492- set . headers [ 'content-length' ] = ( response as string ) . length
507+ set . headers [ 'content-length' ] = Buffer . byteLength (
508+ response as string ,
509+ 'utf8'
510+ )
493511
494512 if ( res ) {
495513 res . writeHead ( set . status ! , set . headers )
@@ -520,7 +538,10 @@ export const mapEarlyResponse = (
520538 switch ( response ?. constructor ?. name ) {
521539 case 'String' :
522540 set . headers [ 'content-type' ] = 'text/plain;charset=utf8'
523- set . headers [ 'content-length' ] = ( response as string ) . length
541+ set . headers [ 'content-length' ] = Buffer . byteLength (
542+ response as string ,
543+ 'utf8'
544+ )
524545
525546 if ( res ) {
526547 res . writeHead ( set . status ! , set . headers )
@@ -534,7 +555,10 @@ export const mapEarlyResponse = (
534555 response = JSON . stringify ( response )
535556
536557 set . headers [ 'content-type' ] = 'application/json;charset=utf8'
537- set . headers [ 'content-length' ] = ( response as string ) . length
558+ set . headers [ 'content-length' ] = Buffer . byteLength (
559+ response as string ,
560+ 'utf8'
561+ )
538562
539563 if ( res ) {
540564 res . writeHead ( set . status ! , set . headers )
@@ -602,7 +626,10 @@ export const mapEarlyResponse = (
602626 response = JSON . stringify ( response )
603627
604628 set . headers [ 'content-type' ] = 'application/json;charset=utf8'
605- set . headers [ 'content-length' ] = ( response as string ) . length
629+ set . headers [ 'content-length' ] = Buffer . byteLength (
630+ response as string ,
631+ 'utf8'
632+ )
606633
607634 return [ response , set as any ]
608635
@@ -640,7 +667,10 @@ export const mapEarlyResponse = (
640667 response = ( response as number | boolean ) . toString ( )
641668
642669 set . headers [ 'content-type' ] = 'text/plain;charset=utf8'
643- set . headers [ 'content-length' ] = ( response as string ) . length
670+ set . headers [ 'content-length' ] = Buffer . byteLength (
671+ response as string ,
672+ 'utf8'
673+ )
644674
645675 if ( res ) {
646676 res . writeHead ( set . status ! , set . headers )
@@ -722,7 +752,10 @@ export const mapEarlyResponse = (
722752 if ( ! set . headers [ 'Content-Type' ] )
723753 set . headers [ 'content-type' ] =
724754 'application/json;charset=utf8'
725- set . headers [ 'content-length' ] = ( response as string ) . length
755+ set . headers [ 'content-length' ] = Buffer . byteLength (
756+ response as string ,
757+ 'utf8'
758+ )
726759
727760 if ( res ) {
728761 res . writeHead ( set . status ! , set . headers )
@@ -734,7 +767,10 @@ export const mapEarlyResponse = (
734767 }
735768
736769 set . headers [ 'content-type' ] = 'text/plain;charset=utf8'
737- set . headers [ 'content-length' ] = ( response as string ) . length
770+ set . headers [ 'content-length' ] = Buffer . byteLength (
771+ response as string ,
772+ 'utf8'
773+ )
738774
739775 if ( res ) {
740776 res . writeHead ( set . status ! , set . headers )
0 commit comments