1- import { isStringSingleLine } from "https://raw.githubusercontent.com/hugoalh/is-string-singleline-es/v1.0.4 /mod.ts" ;
1+ import { isStringSingleLine } from "https://raw.githubusercontent.com/hugoalh/is-string-singleline-es/v1.0.5 /mod.ts" ;
22const parametersNeedLowerCase : string [ ] = [
33 "rel" ,
44 "type"
@@ -139,7 +139,7 @@ export class HTTPHeaderLink {
139139 * Handle the HTTP header `Link` according to the specification RFC 8288.
140140 * @param {...(string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response) } inputs Input.
141141 */
142- constructor ( ...inputs : ( string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry [ ] | Response ) [ ] ) {
142+ constructor ( ...inputs : readonly ( string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry [ ] | Response ) [ ] ) {
143143 if ( inputs . length > 0 ) {
144144 this . add ( ...inputs ) ;
145145 }
@@ -149,7 +149,7 @@ export class HTTPHeaderLink {
149149 * @param {...(string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response) } inputs Input.
150150 * @returns {this }
151151 */
152- add ( ...inputs : ( string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry [ ] | Response ) [ ] ) : this {
152+ add ( ...inputs : readonly ( string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry [ ] | Response ) [ ] ) : this {
153153 for ( const input of inputs ) {
154154 if ( input instanceof HTTPHeaderLink ) {
155155 this . #entries. push ( ...structuredClone ( input . #entries) ) ;
@@ -170,10 +170,15 @@ export class HTTPHeaderLink {
170170 return [ uri , structuredClone ( parameters ) ] ;
171171 } ) ) ;
172172 } else {
173- for ( const entry of parseLinkFromString ( ( (
174- input instanceof Headers ||
175- input instanceof Response
176- ) ? ( ( input instanceof Headers ) ? input : input . headers ) . get ( "Link" ) : input ) ?? "" ) ) {
173+ let inputFmt : string ;
174+ if ( input instanceof Response ) {
175+ inputFmt = input . headers . get ( "Link" ) ?? "" ;
176+ } else if ( input instanceof Headers ) {
177+ inputFmt = input . get ( "Link" ) ?? "" ;
178+ } else {
179+ inputFmt = input ;
180+ }
181+ for ( const entry of parseLinkFromString ( inputFmt ) ) {
177182 this . #entries. push ( entry ) ;
178183 }
179184 }
@@ -245,15 +250,15 @@ export class HTTPHeaderLink {
245250 * @param {...(string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response) } inputs Input.
246251 * @returns {HTTPHeaderLink }
247252 */
248- static parse ( ...inputs : ( string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry [ ] | Response ) [ ] ) : HTTPHeaderLink {
253+ static parse ( ...inputs : readonly ( string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry [ ] | Response ) [ ] ) : HTTPHeaderLink {
249254 return new this ( ...inputs ) ;
250255 }
251256 /**
252257 * Stringify as the HTTP header `Link` according to the specification RFC 8288.
253258 * @param {...(string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response) } inputs Input.
254259 * @returns {string }
255260 */
256- static stringify ( ...inputs : ( string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry [ ] | Response ) [ ] ) : string {
261+ static stringify ( ...inputs : readonly ( string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry [ ] | Response ) [ ] ) : string {
257262 return new this ( ...inputs ) . toString ( ) ;
258263 }
259264}
0 commit comments