@@ -19,6 +19,7 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
1919 return prototype === Object . prototype || prototype === null ;
2020}
2121
22+ /** Minimal `Headers` implementation used by the public API. */
2223export class Headers implements Iterable < HeaderTuple > {
2324 private readonly store = new Map < string , HeaderEntry > ( ) ;
2425 private entriesList : HeaderTuple [ ] = [ ] ;
@@ -69,6 +70,7 @@ export class Headers implements Iterable<HeaderTuple> {
6970 return { key : trimmed . toLowerCase ( ) , display : trimmed } ;
7071 }
7172
73+ /** Appends a header value without removing existing values for the same name. */
7274 append ( name : string , value : unknown ) : void {
7375 const normalized = this . normalizeName ( name ) ;
7476 const entry = this . store . get ( normalized . key ) ;
@@ -88,6 +90,7 @@ export class Headers implements Iterable<HeaderTuple> {
8890 } ) ;
8991 }
9092
93+ /** Replaces all existing values for a header name. */
9194 set ( name : string , value : unknown ) : void {
9295 const normalized = this . normalizeName ( name ) ;
9396 const stringValue = String ( value ) ;
@@ -100,22 +103,26 @@ export class Headers implements Iterable<HeaderTuple> {
100103 name : normalized . display ,
101104 values : [ stringValue ] ,
102105 } ) ;
106+
103107 this . entriesList . push ( [ normalized . display , stringValue ] ) ;
104108 }
105109
110+ /** Returns the combined header value for `name`, or `null` when absent. */
106111 get ( name : string ) : string | null {
107112 const normalized = this . normalizeName ( name ) ;
108113 const entry = this . store . get ( normalized . key ) ;
109114
110115 return entry ? entry . values . join ( ', ' ) : null ;
111116 }
112117
118+ /** Returns `true` when the header collection contains `name`. */
113119 has ( name : string ) : boolean {
114120 const normalized = this . normalizeName ( name ) ;
115121
116122 return this . store . has ( normalized . key ) ;
117123 }
118124
125+ /** Removes all values associated with `name`. */
119126 delete ( name : string ) : void {
120127 const normalized = this . normalizeName ( name ) ;
121128
@@ -125,6 +132,7 @@ export class Headers implements Iterable<HeaderTuple> {
125132 ) ;
126133 }
127134
135+ /** Converts the header collection into a plain object. */
128136 toObject ( ) : Record < string , string > {
129137 const result : Record < string , string > = { } ;
130138
@@ -135,10 +143,12 @@ export class Headers implements Iterable<HeaderTuple> {
135143 return result ;
136144 }
137145
146+ /** Returns headers as ordered `[name, value]` tuples. */
138147 toTuples ( ) : HeaderTuple [ ] {
139148 return this . entriesList . map ( ( [ name , value ] ) => [ name , value ] ) ;
140149 }
141150
151+ /** Returns unique header names preserving their original casing. */
142152 toOriginalNames ( ) : string [ ] {
143153 const names : string [ ] = [ ] ;
144154 const seen = new Set < string > ( ) ;
@@ -157,12 +167,14 @@ export class Headers implements Iterable<HeaderTuple> {
157167 return names ;
158168 }
159169
170+ /** Iterates over normalized `[name, value]` header entries. */
160171 * entries ( ) : IterableIterator < HeaderTuple > {
161172 for ( const entry of this . store . values ( ) ) {
162173 yield [ entry . name , entry . values . join ( ', ' ) ] ;
163174 }
164175 }
165176
177+ /** Iterates over normalized `[name, value]` header entries. */
166178 [ Symbol . iterator ] ( ) : IterableIterator < HeaderTuple > {
167179 return this . entries ( ) ;
168180 }
0 commit comments