@@ -382,11 +382,11 @@ export class SuperHeaders extends Headers {
382
382
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7233#section-2.3)
383
383
*/
384
384
get acceptRanges ( ) : string | null {
385
- return this . get ( 'accept-ranges' ) ;
385
+ return this . #getStringValue ( 'accept-ranges' ) ;
386
386
}
387
387
388
388
set acceptRanges ( value : string | undefined | null ) {
389
- this . #setValue ( 'accept-ranges' , value ) ;
389
+ this . #setStringValue ( 'accept-ranges' , value ) ;
390
390
}
391
391
392
392
/**
@@ -428,11 +428,11 @@ export class SuperHeaders extends Headers {
428
428
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7230#section-6.1)
429
429
*/
430
430
get connection ( ) : string | null {
431
- return this . get ( 'connection' ) ;
431
+ return this . #getStringValue ( 'connection' ) ;
432
432
}
433
433
434
434
set connection ( value : string | undefined | null ) {
435
- this . #setValue ( 'connection' , value ) ;
435
+ this . #setStringValue ( 'connection' , value ) ;
436
436
}
437
437
438
438
/**
@@ -461,11 +461,11 @@ export class SuperHeaders extends Headers {
461
461
* [HTTP/1.1 Specification](https://httpwg.org/specs/rfc9110.html#field.content-encoding)
462
462
*/
463
463
get contentEncoding ( ) : string | null {
464
- return this . get ( 'content-encoding' ) ;
464
+ return this . #getStringValue ( 'content-encoding' ) ;
465
465
}
466
466
467
467
set contentEncoding ( value : string | string [ ] | undefined | null ) {
468
- this . #setValue ( 'content-encoding' , Array . isArray ( value ) ? value . join ( ', ' ) : value ) ;
468
+ this . #setStringValue ( 'content-encoding' , Array . isArray ( value ) ? value . join ( ', ' ) : value ) ;
469
469
}
470
470
471
471
/**
@@ -479,11 +479,11 @@ export class SuperHeaders extends Headers {
479
479
* [HTTP/1.1 Specification](https://httpwg.org/specs/rfc9110.html#field.content-language)
480
480
*/
481
481
get contentLanguage ( ) : string | null {
482
- return this . get ( 'content-language' ) ;
482
+ return this . #getStringValue ( 'content-language' ) ;
483
483
}
484
484
485
485
set contentLanguage ( value : string | string [ ] | undefined | null ) {
486
- this . #setValue ( 'content-language' , Array . isArray ( value ) ? value . join ( ', ' ) : value ) ;
486
+ this . #setStringValue ( 'content-language' , Array . isArray ( value ) ? value . join ( ', ' ) : value ) ;
487
487
}
488
488
489
489
/**
@@ -555,11 +555,11 @@ export class SuperHeaders extends Headers {
555
555
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7232#section-2.3)
556
556
*/
557
557
get etag ( ) : string | null {
558
- return this . get ( 'etag' ) ;
558
+ return this . #getStringValue ( 'etag' ) ;
559
559
}
560
560
561
561
set etag ( value : string | undefined | null ) {
562
- this . #setValue (
562
+ this . #setStringValue (
563
563
'etag' ,
564
564
typeof value === 'string' && ! / ^ ( W \/ ) ? " .* " $ / . test ( value ) ? `"${ value } "` : value ,
565
565
) ;
@@ -588,11 +588,11 @@ export class SuperHeaders extends Headers {
588
588
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7230#section-5.4)
589
589
*/
590
590
get host ( ) : string | null {
591
- return this . get ( 'host' ) ;
591
+ return this . #getStringValue ( 'host' ) ;
592
592
}
593
593
594
594
set host ( value : string | undefined | null ) {
595
- this . #setValue ( 'host' , value ) ;
595
+ this . #setStringValue ( 'host' , value ) ;
596
596
}
597
597
598
598
/**
@@ -650,11 +650,11 @@ export class SuperHeaders extends Headers {
650
650
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.2)
651
651
*/
652
652
get location ( ) : string | null {
653
- return this . get ( 'location' ) ;
653
+ return this . #getStringValue ( 'location' ) ;
654
654
}
655
655
656
656
set location ( value : string | undefined | null ) {
657
- this . #setValue ( 'location' , value ) ;
657
+ this . #setStringValue ( 'location' , value ) ;
658
658
}
659
659
660
660
/**
@@ -666,11 +666,11 @@ export class SuperHeaders extends Headers {
666
666
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-5.5.2)
667
667
*/
668
668
get referer ( ) : string | null {
669
- return this . get ( 'referer' ) ;
669
+ return this . #getStringValue ( 'referer' ) ;
670
670
}
671
671
672
672
set referer ( value : string | undefined | null ) {
673
- this . #setValue ( 'referer' , value ) ;
673
+ this . #setStringValue ( 'referer' , value ) ;
674
674
}
675
675
676
676
/**
@@ -707,14 +707,6 @@ export class SuperHeaders extends Headers {
707
707
708
708
// helpers
709
709
710
- #setValue( key : string , value : string | undefined | null ) : void {
711
- if ( value != null ) {
712
- this . #map. set ( key , value ) ;
713
- } else {
714
- this . #map. delete ( key ) ;
715
- }
716
- }
717
-
718
710
#getHeaderValue< T extends HeaderValue > ( key : string , ctor : new ( init ?: any ) => T ) : T {
719
711
let value = this . #map. get ( key ) ;
720
712
@@ -771,4 +763,17 @@ export class SuperHeaders extends Headers {
771
763
this . #map. delete ( key ) ;
772
764
}
773
765
}
766
+
767
+ #getStringValue( key : string ) : string | null {
768
+ let value = this . #map. get ( key ) ;
769
+ return value === undefined ? null : ( value as string ) ;
770
+ }
771
+
772
+ #setStringValue( key : string , value : string | undefined | null ) : void {
773
+ if ( value != null ) {
774
+ this . #map. set ( key , value ) ;
775
+ } else {
776
+ this . #map. delete ( key ) ;
777
+ }
778
+ }
774
779
}
0 commit comments