MCPcopy Create free account
hub / github.com/WICG/webpackage / HeaderMap

Class HeaderMap

js/bundle/src/encoder.ts:243–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241}
242
243class 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).

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected