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

Function decodeResponseMap

js/bundle/src/decoder.ts:210–235  ·  view source on GitHub ↗
(cbor: Uint8Array)

Source from the content-addressed store, hash-verified

208}
209
210function decodeResponseMap(cbor: Uint8Array): {
211 status: number;
212 headers: Headers;
213} {
214 const decoded = cborg.decode(cbor, { useMaps: true });
215 if (!(decoded instanceof Map)) {
216 throw new Error('Wrong header map structure');
217 }
218 let status: number | null = null;
219 const headers: Headers = {};
220 for (let [key, val] of decoded.entries()) {
221 key = bytestringToString(key);
222 val = bytestringToString(val);
223 if (key === ':status') {
224 status = Number(val);
225 } else if (key.startsWith(':')) {
226 throw new Error('Unknown psuedo header ' + key);
227 } else {
228 headers[key] = val;
229 }
230 }
231 if (!status) {
232 throw new Error('No :status in response header map');
233 }
234 return { status, headers };
235}
236
237// Type assertions and conversions for CBOR-decoded objects.
238

Callers 1

constructorMethod · 0.85

Calls 1

bytestringToStringFunction · 0.85

Tested by

no test coverage detected