@@ -263,7 +263,10 @@ export const mapResponse = (
263
263
set . headers [ 'content-type' ] = 'text/plain;charset=utf8'
264
264
265
265
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
+ )
267
270
res . writeHead ( set . status ! , set . headers )
268
271
res . end ( response )
269
272
}
@@ -275,7 +278,10 @@ export const mapResponse = (
275
278
response = JSON . stringify ( response )
276
279
277
280
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
+ )
279
285
280
286
if ( res ) {
281
287
res . writeHead ( set . status ! , set . headers )
@@ -349,7 +355,10 @@ export const mapResponse = (
349
355
response = JSON . stringify ( response )
350
356
351
357
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
+ )
353
362
354
363
if ( res ) {
355
364
res . writeHead ( set . status ! , set . headers )
@@ -392,7 +401,10 @@ export const mapResponse = (
392
401
response = ( response as number | boolean ) . toString ( )
393
402
394
403
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
+ )
396
408
397
409
if ( res ) {
398
410
res . writeHead ( set . status ! , set . headers )
@@ -474,7 +486,10 @@ export const mapResponse = (
474
486
'application/json;charset=utf8'
475
487
476
488
response = JSON . stringify ( response )
477
- set . headers [ 'content-length' ] = ( response as string ) . length
489
+ set . headers [ 'content-length' ] = Buffer . byteLength (
490
+ response as string ,
491
+ 'utf8'
492
+ )
478
493
479
494
if ( res ) {
480
495
res . writeHead ( set . status ! , set . headers )
@@ -486,7 +501,10 @@ export const mapResponse = (
486
501
}
487
502
488
503
set . headers [ 'content-type' ] = 'text/plain;charset=utf8'
489
- set . headers [ 'content-length' ] = ( response as string ) . length
504
+ set . headers [ 'content-length' ] = Buffer . byteLength (
505
+ response as string ,
506
+ 'utf8'
507
+ )
490
508
491
509
if ( res ) {
492
510
res . writeHead ( set . status ! , set . headers )
@@ -517,7 +535,10 @@ export const mapEarlyResponse = (
517
535
switch ( response ?. constructor ?. name ) {
518
536
case 'String' :
519
537
set . headers [ 'content-type' ] = 'text/plain;charset=utf8'
520
- set . headers [ 'content-length' ] = ( response as string ) . length
538
+ set . headers [ 'content-length' ] = Buffer . byteLength (
539
+ response as string ,
540
+ 'utf8'
541
+ )
521
542
522
543
if ( res ) {
523
544
res . writeHead ( set . status ! , set . headers )
@@ -531,7 +552,10 @@ export const mapEarlyResponse = (
531
552
response = JSON . stringify ( response )
532
553
533
554
set . headers [ 'content-type' ] = 'application/json;charset=utf8'
534
- set . headers [ 'content-length' ] = ( response as string ) . length
555
+ set . headers [ 'content-length' ] = Buffer . byteLength (
556
+ response as string ,
557
+ 'utf8'
558
+ )
535
559
536
560
if ( res ) {
537
561
res . writeHead ( set . status ! , set . headers )
@@ -599,7 +623,10 @@ export const mapEarlyResponse = (
599
623
response = JSON . stringify ( response )
600
624
601
625
set . headers [ 'content-type' ] = 'application/json;charset=utf8'
602
- set . headers [ 'content-length' ] = ( response as string ) . length
626
+ set . headers [ 'content-length' ] = Buffer . byteLength (
627
+ response as string ,
628
+ 'utf8'
629
+ )
603
630
604
631
return [ response , set as any ]
605
632
@@ -637,7 +664,10 @@ export const mapEarlyResponse = (
637
664
response = ( response as number | boolean ) . toString ( )
638
665
639
666
set . headers [ 'content-type' ] = 'text/plain;charset=utf8'
640
- set . headers [ 'content-length' ] = ( response as string ) . length
667
+ set . headers [ 'content-length' ] = Buffer . byteLength (
668
+ response as string ,
669
+ 'utf8'
670
+ )
641
671
642
672
if ( res ) {
643
673
res . writeHead ( set . status ! , set . headers )
@@ -716,7 +746,10 @@ export const mapEarlyResponse = (
716
746
if ( ! set . headers [ 'Content-Type' ] )
717
747
set . headers [ 'content-type' ] =
718
748
'application/json;charset=utf8'
719
- set . headers [ 'content-length' ] = ( response as string ) . length
749
+ set . headers [ 'content-length' ] = Buffer . byteLength (
750
+ response as string ,
751
+ 'utf8'
752
+ )
720
753
721
754
if ( res ) {
722
755
res . writeHead ( set . status ! , set . headers )
@@ -728,7 +761,10 @@ export const mapEarlyResponse = (
728
761
}
729
762
730
763
set . headers [ 'content-type' ] = 'text/plain;charset=utf8'
731
- set . headers [ 'content-length' ] = ( response as string ) . length
764
+ set . headers [ 'content-length' ] = Buffer . byteLength (
765
+ response as string ,
766
+ 'utf8'
767
+ )
732
768
733
769
if ( res ) {
734
770
res . writeHead ( set . status ! , set . headers )
0 commit comments