(cbor: Uint8Array)
| 208 | } |
| 209 | |
| 210 | function 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 |
no test coverage detected