| 241 | } |
| 242 | |
| 243 | class HeaderMap extends Map<string, string> { |
| 244 | constructor(status: number, headers: Headers) { |
| 245 | super(); |
| 246 | if (status < 100 || status > 999) { |
| 247 | throw new Error('Invalid status code'); |
| 248 | } |
| 249 | |
| 250 | this.set(':status', status.toString()); |
| 251 | for (const key of Object.keys(headers)) { |
| 252 | this.set(key.toLowerCase(), headers[key]); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | toCBOR(): Uint8Array { |
| 257 | // Convert keys and values to Uint8Array, as the CBOR representation of |
| 258 | // header map is {bytestring => bytestring}. |
| 259 | const m = new Map<Uint8Array, Uint8Array>(); |
| 260 | for (const [key, value] of this.entries()) { |
| 261 | m.set(byteString(key), byteString(value)); |
| 262 | } |
| 263 | return cborg.encode(m); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // Throws an error if `urlString` is not a valid exchange URL, i.e. it must not |
| 268 | // have credentials (user:password@) or hash (#fragment). |
nothing calls this directly
no outgoing calls
no test coverage detected