@@ -10,9 +10,6 @@ import { type HeaderValue } from './header-value.ts';
10
10
import { type SetCookieInit , SetCookie } from './set-cookie.ts' ;
11
11
import { isIterable } from './utils.ts' ;
12
12
13
- const CRLF = '\r\n' ;
14
- const SetCookieKey = 'set-cookie' ;
15
-
16
13
type DateInit = number | Date ;
17
14
18
15
interface SuperHeadersPropertyInit {
@@ -114,6 +111,32 @@ export type SuperHeadersInit =
114
111
| Iterable < [ string , string ] >
115
112
| ( SuperHeadersPropertyInit & Record < string , string | HeaderValue > ) ;
116
113
114
+ const CRLF = '\r\n' ;
115
+
116
+ const AcceptKey = 'accept' ;
117
+ const AcceptEncodingKey = 'accept-encoding' ;
118
+ const AcceptLanguageKey = 'accept-language' ;
119
+ const AcceptRangesKey = 'accept-ranges' ;
120
+ const AgeKey = 'age' ;
121
+ const CacheControlKey = 'cache-control' ;
122
+ const ConnectionKey = 'connection' ;
123
+ const ContentDispositionKey = 'content-disposition' ;
124
+ const ContentEncodingKey = 'content-encoding' ;
125
+ const ContentLanguageKey = 'content-language' ;
126
+ const ContentLengthKey = 'content-length' ;
127
+ const ContentTypeKey = 'content-type' ;
128
+ const CookieKey = 'cookie' ;
129
+ const DateKey = 'date' ;
130
+ const ETagKey = 'etag' ;
131
+ const ExpiresKey = 'expires' ;
132
+ const HostKey = 'host' ;
133
+ const IfModifiedSinceKey = 'if-modified-since' ;
134
+ const IfUnmodifiedSinceKey = 'if-unmodified-since' ;
135
+ const LastModifiedKey = 'last-modified' ;
136
+ const LocationKey = 'location' ;
137
+ const RefererKey = 'referer' ;
138
+ const SetCookieKey = 'set-cookie' ;
139
+
117
140
/**
118
141
* An enhanced JavaScript `Headers` interface with type-safe access.
119
142
*
@@ -335,11 +358,11 @@ export class SuperHeaders extends Headers {
335
358
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2)
336
359
*/
337
360
get accept ( ) : Accept {
338
- return this . #getHeaderValue( 'accept' , Accept ) ;
361
+ return this . #getHeaderValue( AcceptKey , Accept ) ;
339
362
}
340
363
341
364
set accept ( value : string | AcceptInit | undefined | null ) {
342
- this . #setHeaderValue( 'accept' , Accept , value ) ;
365
+ this . #setHeaderValue( AcceptKey , Accept , value ) ;
343
366
}
344
367
345
368
/**
@@ -351,11 +374,11 @@ export class SuperHeaders extends Headers {
351
374
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.4)
352
375
*/
353
376
get acceptEncoding ( ) : AcceptEncoding {
354
- return this . #getHeaderValue( 'accept-encoding' , AcceptEncoding ) ;
377
+ return this . #getHeaderValue( AcceptEncodingKey , AcceptEncoding ) ;
355
378
}
356
379
357
380
set acceptEncoding ( value : string | AcceptEncodingInit | undefined | null ) {
358
- this . #setHeaderValue( 'accept-encoding' , AcceptEncoding , value ) ;
381
+ this . #setHeaderValue( AcceptEncodingKey , AcceptEncoding , value ) ;
359
382
}
360
383
361
384
/**
@@ -367,11 +390,11 @@ export class SuperHeaders extends Headers {
367
390
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.5)
368
391
*/
369
392
get acceptLanguage ( ) : AcceptLanguage {
370
- return this . #getHeaderValue( 'accept-language' , AcceptLanguage ) ;
393
+ return this . #getHeaderValue( AcceptLanguageKey , AcceptLanguage ) ;
371
394
}
372
395
373
396
set acceptLanguage ( value : string | AcceptLanguageInit | undefined | null ) {
374
- this . #setHeaderValue( 'accept-language' , AcceptLanguage , value ) ;
397
+ this . #setHeaderValue( AcceptLanguageKey , AcceptLanguage , value ) ;
375
398
}
376
399
377
400
/**
@@ -382,11 +405,11 @@ export class SuperHeaders extends Headers {
382
405
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7233#section-2.3)
383
406
*/
384
407
get acceptRanges ( ) : string | null {
385
- return this . #getStringValue( 'accept-ranges' ) ;
408
+ return this . #getStringValue( AcceptRangesKey ) ;
386
409
}
387
410
388
411
set acceptRanges ( value : string | undefined | null ) {
389
- this . #setStringValue( 'accept-ranges' , value ) ;
412
+ this . #setStringValue( AcceptRangesKey , value ) ;
390
413
}
391
414
392
415
/**
@@ -397,11 +420,11 @@ export class SuperHeaders extends Headers {
397
420
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7234#section-5.1)
398
421
*/
399
422
get age ( ) : number | null {
400
- return this . #getNumberValue( 'age' ) ;
423
+ return this . #getNumberValue( AgeKey ) ;
401
424
}
402
425
403
426
set age ( value : string | number | undefined | null ) {
404
- this . #setNumberValue( 'age' , value ) ;
427
+ this . #setNumberValue( AgeKey , value ) ;
405
428
}
406
429
407
430
/**
@@ -412,11 +435,11 @@ export class SuperHeaders extends Headers {
412
435
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7234#section-5.2)
413
436
*/
414
437
get cacheControl ( ) : CacheControl {
415
- return this . #getHeaderValue( 'cache-control' , CacheControl ) ;
438
+ return this . #getHeaderValue( CacheControlKey , CacheControl ) ;
416
439
}
417
440
418
441
set cacheControl ( value : string | CacheControlInit | undefined | null ) {
419
- this . #setHeaderValue( 'cache-control' , CacheControl , value ) ;
442
+ this . #setHeaderValue( CacheControlKey , CacheControl , value ) ;
420
443
}
421
444
422
445
/**
@@ -428,11 +451,11 @@ export class SuperHeaders extends Headers {
428
451
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7230#section-6.1)
429
452
*/
430
453
get connection ( ) : string | null {
431
- return this . #getStringValue( 'connection' ) ;
454
+ return this . #getStringValue( ConnectionKey ) ;
432
455
}
433
456
434
457
set connection ( value : string | undefined | null ) {
435
- this . #setStringValue( 'connection' , value ) ;
458
+ this . #setStringValue( ConnectionKey , value ) ;
436
459
}
437
460
438
461
/**
@@ -443,11 +466,11 @@ export class SuperHeaders extends Headers {
443
466
* [RFC 6266](https://datatracker.ietf.org/doc/html/rfc6266)
444
467
*/
445
468
get contentDisposition ( ) : ContentDisposition {
446
- return this . #getHeaderValue( 'content-disposition' , ContentDisposition ) ;
469
+ return this . #getHeaderValue( ContentDispositionKey , ContentDisposition ) ;
447
470
}
448
471
449
472
set contentDisposition ( value : string | ContentDispositionInit | undefined | null ) {
450
- this . #setHeaderValue( 'content-disposition' , ContentDisposition , value ) ;
473
+ this . #setHeaderValue( ContentDispositionKey , ContentDisposition , value ) ;
451
474
}
452
475
453
476
/**
@@ -461,11 +484,11 @@ export class SuperHeaders extends Headers {
461
484
* [HTTP/1.1 Specification](https://httpwg.org/specs/rfc9110.html#field.content-encoding)
462
485
*/
463
486
get contentEncoding ( ) : string | null {
464
- return this . #getStringValue( 'content-encoding' ) ;
487
+ return this . #getStringValue( ContentEncodingKey ) ;
465
488
}
466
489
467
490
set contentEncoding ( value : string | string [ ] | undefined | null ) {
468
- this . #setStringValue( 'content-encoding' , Array . isArray ( value ) ? value . join ( ', ' ) : value ) ;
491
+ this . #setStringValue( ContentEncodingKey , Array . isArray ( value ) ? value . join ( ', ' ) : value ) ;
469
492
}
470
493
471
494
/**
@@ -479,11 +502,11 @@ export class SuperHeaders extends Headers {
479
502
* [HTTP/1.1 Specification](https://httpwg.org/specs/rfc9110.html#field.content-language)
480
503
*/
481
504
get contentLanguage ( ) : string | null {
482
- return this . #getStringValue( 'content-language' ) ;
505
+ return this . #getStringValue( ContentLanguageKey ) ;
483
506
}
484
507
485
508
set contentLanguage ( value : string | string [ ] | undefined | null ) {
486
- this . #setStringValue( 'content-language' , Array . isArray ( value ) ? value . join ( ', ' ) : value ) ;
509
+ this . #setStringValue( ContentLanguageKey , Array . isArray ( value ) ? value . join ( ', ' ) : value ) ;
487
510
}
488
511
489
512
/**
@@ -494,11 +517,11 @@ export class SuperHeaders extends Headers {
494
517
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.2)
495
518
*/
496
519
get contentLength ( ) : number | null {
497
- return this . #getNumberValue( 'content-length' ) ;
520
+ return this . #getNumberValue( ContentLengthKey ) ;
498
521
}
499
522
500
523
set contentLength ( value : string | number | undefined | null ) {
501
- this . #setNumberValue( 'content-length' , value ) ;
524
+ this . #setNumberValue( ContentLengthKey , value ) ;
502
525
}
503
526
504
527
/**
@@ -509,11 +532,11 @@ export class SuperHeaders extends Headers {
509
532
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.1.5)
510
533
*/
511
534
get contentType ( ) : ContentType {
512
- return this . #getHeaderValue( 'content-type' , ContentType ) ;
535
+ return this . #getHeaderValue( ContentTypeKey , ContentType ) ;
513
536
}
514
537
515
538
set contentType ( value : string | ContentTypeInit | undefined | null ) {
516
- this . #setHeaderValue( 'content-type' , ContentType , value ) ;
539
+ this . #setHeaderValue( ContentTypeKey , ContentType , value ) ;
517
540
}
518
541
519
542
/**
@@ -525,11 +548,11 @@ export class SuperHeaders extends Headers {
525
548
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc6265#section-5.4)
526
549
*/
527
550
get cookie ( ) : Cookie {
528
- return this . #getHeaderValue( 'cookie' , Cookie ) ;
551
+ return this . #getHeaderValue( CookieKey , Cookie ) ;
529
552
}
530
553
531
554
set cookie ( value : string | CookieInit | undefined | null ) {
532
- this . #setHeaderValue( 'cookie' , Cookie , value ) ;
555
+ this . #setHeaderValue( CookieKey , Cookie , value ) ;
533
556
}
534
557
535
558
/**
@@ -540,11 +563,11 @@ export class SuperHeaders extends Headers {
540
563
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.1.2)
541
564
*/
542
565
get date ( ) : Date | null {
543
- return this . #getDateValue( 'date' ) ;
566
+ return this . #getDateValue( DateKey ) ;
544
567
}
545
568
546
569
set date ( value : string | DateInit | undefined | null ) {
547
- this . #setDateValue( 'date' , value ) ;
570
+ this . #setDateValue( DateKey , value ) ;
548
571
}
549
572
550
573
/**
@@ -555,12 +578,12 @@ export class SuperHeaders extends Headers {
555
578
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7232#section-2.3)
556
579
*/
557
580
get etag ( ) : string | null {
558
- return this . #getStringValue( 'etag' ) ;
581
+ return this . #getStringValue( ETagKey ) ;
559
582
}
560
583
561
584
set etag ( value : string | undefined | null ) {
562
585
this . #setStringValue(
563
- 'etag' ,
586
+ ETagKey ,
564
587
typeof value === 'string' && ! / ^ ( W \/ ) ? " .* " $ / . test ( value ) ? `"${ value } "` : value ,
565
588
) ;
566
589
}
@@ -573,11 +596,11 @@ export class SuperHeaders extends Headers {
573
596
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7234#section-5.3)
574
597
*/
575
598
get expires ( ) : Date | null {
576
- return this . #getDateValue( 'expires' ) ;
599
+ return this . #getDateValue( ExpiresKey ) ;
577
600
}
578
601
579
602
set expires ( value : string | DateInit | undefined | null ) {
580
- this . #setDateValue( 'expires' , value ) ;
603
+ this . #setDateValue( ExpiresKey , value ) ;
581
604
}
582
605
583
606
/**
@@ -588,11 +611,11 @@ export class SuperHeaders extends Headers {
588
611
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7230#section-5.4)
589
612
*/
590
613
get host ( ) : string | null {
591
- return this . #getStringValue( 'host' ) ;
614
+ return this . #getStringValue( HostKey ) ;
592
615
}
593
616
594
617
set host ( value : string | undefined | null ) {
595
- this . #setStringValue( 'host' , value ) ;
618
+ this . #setStringValue( HostKey , value ) ;
596
619
}
597
620
598
621
/**
@@ -604,11 +627,11 @@ export class SuperHeaders extends Headers {
604
627
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7232#section-3.3)
605
628
*/
606
629
get ifModifiedSince ( ) : Date | null {
607
- return this . #getDateValue( 'if-modified-since' ) ;
630
+ return this . #getDateValue( IfModifiedSinceKey ) ;
608
631
}
609
632
610
633
set ifModifiedSince ( value : string | DateInit | undefined | null ) {
611
- this . #setDateValue( 'if-modified-since' , value ) ;
634
+ this . #setDateValue( IfModifiedSinceKey , value ) ;
612
635
}
613
636
614
637
/**
@@ -620,11 +643,11 @@ export class SuperHeaders extends Headers {
620
643
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7232#section-3.4)
621
644
*/
622
645
get ifUnmodifiedSince ( ) : Date | null {
623
- return this . #getDateValue( 'if-unmodified-since' ) ;
646
+ return this . #getDateValue( IfUnmodifiedSinceKey ) ;
624
647
}
625
648
626
649
set ifUnmodifiedSince ( value : string | DateInit | undefined | null ) {
627
- this . #setDateValue( 'if-unmodified-since' , value ) ;
650
+ this . #setDateValue( IfUnmodifiedSinceKey , value ) ;
628
651
}
629
652
630
653
/**
@@ -635,11 +658,11 @@ export class SuperHeaders extends Headers {
635
658
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7232#section-2.2)
636
659
*/
637
660
get lastModified ( ) : Date | null {
638
- return this . #getDateValue( 'last-modified' ) ;
661
+ return this . #getDateValue( LastModifiedKey ) ;
639
662
}
640
663
641
664
set lastModified ( value : string | DateInit | undefined | null ) {
642
- this . #setDateValue( 'last-modified' , value ) ;
665
+ this . #setDateValue( LastModifiedKey , value ) ;
643
666
}
644
667
645
668
/**
@@ -650,11 +673,11 @@ export class SuperHeaders extends Headers {
650
673
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.2)
651
674
*/
652
675
get location ( ) : string | null {
653
- return this . #getStringValue( 'location' ) ;
676
+ return this . #getStringValue( LocationKey ) ;
654
677
}
655
678
656
679
set location ( value : string | undefined | null ) {
657
- this . #setStringValue( 'location' , value ) ;
680
+ this . #setStringValue( LocationKey , value ) ;
658
681
}
659
682
660
683
/**
@@ -666,11 +689,11 @@ export class SuperHeaders extends Headers {
666
689
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-5.5.2)
667
690
*/
668
691
get referer ( ) : string | null {
669
- return this . #getStringValue( 'referer' ) ;
692
+ return this . #getStringValue( RefererKey ) ;
670
693
}
671
694
672
695
set referer ( value : string | undefined | null ) {
673
- this . #setStringValue( 'referer' , value ) ;
696
+ this . #setStringValue( RefererKey , value ) ;
674
697
}
675
698
676
699
/**
0 commit comments