https://wpack-wg.github.io/bundled-responses/draft-ietf-wpack-bundled-responses.html#name-the-index-section
(sectionContents []byte, sectionsStart uint64, sos []sectionOffset)
| 204 | |
| 205 | // https://wpack-wg.github.io/bundled-responses/draft-ietf-wpack-bundled-responses.html#name-the-index-section |
| 206 | func parseIndexSectionWithVariants(sectionContents []byte, sectionsStart uint64, sos []sectionOffset) ([]requestEntryWithOffset, error) { |
| 207 | dec := cbor.NewDecoder(bytes.NewBuffer(sectionContents)) |
| 208 | numUrls, err := dec.DecodeMapHeader() |
| 209 | if err != nil { |
| 210 | return nil, fmt.Errorf("bundle.index: failed to decode index section map header: %v", err) |
| 211 | } |
| 212 | requests := []requestEntryWithOffset{} |
| 213 | |
| 214 | respso, respSectionRelOffset, found := FindSection(sos, "responses") |
| 215 | if !found { |
| 216 | return nil, fmt.Errorf("bundle.index: \"responses\" section not found") |
| 217 | } |
| 218 | respSectionOffset := sectionsStart + respSectionRelOffset |
| 219 | makeRelativeToStream := func(offset, length uint64) (uint64, uint64, error) { |
| 220 | if offset+length > respso.Length { |
| 221 | return 0, 0, errors.New("bundle.index: response length out-of-range") |
| 222 | } |
| 223 | return respSectionOffset + offset, length, nil |
| 224 | } |
| 225 | |
| 226 | for i := uint64(0); i < numUrls; i++ { |
| 227 | rawUrl, err := dec.DecodeTextString() |
| 228 | if err != nil { |
| 229 | return nil, fmt.Errorf("bundle.index[%d]: Failed to decode map key: %v", i, err) |
| 230 | } |
| 231 | parsedUrl, err := url.Parse(rawUrl) |
| 232 | if err != nil { |
| 233 | return nil, fmt.Errorf("bundle.index[%d]: Failed to parse URL: %v", i, err) |
| 234 | } |
| 235 | if parsedUrl.Fragment != "" { |
| 236 | return nil, fmt.Errorf("bundle.index[%d]: URL contains fragment: %q", i, rawUrl) |
| 237 | } |
| 238 | if parsedUrl.User != nil { |
| 239 | return nil, fmt.Errorf("bundle.index[%d]: URL contains credentials: %q", i, rawUrl) |
| 240 | } |
| 241 | |
| 242 | numItems, err := dec.DecodeArrayHeader() |
| 243 | if err != nil { |
| 244 | return nil, fmt.Errorf("bundle.index[%d]: Failed to decode value array header: %v", i, err) |
| 245 | } |
| 246 | if numItems == 0 { |
| 247 | return nil, fmt.Errorf("bundle.index[%d]: value array must not be empty.", i) |
| 248 | } |
| 249 | variants_value, err := dec.DecodeByteString() |
| 250 | if err != nil { |
| 251 | return nil, fmt.Errorf("bundle.index[%d]: Failed to decode variants-value: %v", i, err) |
| 252 | } |
| 253 | if len(variants_value) == 0 { |
| 254 | if numItems != 3 { |
| 255 | return nil, fmt.Errorf("bundle.index[%d]: The size of value array must be 3", i) |
| 256 | } |
| 257 | offset, err := dec.DecodeUint() |
| 258 | if err != nil { |
| 259 | return nil, fmt.Errorf("bundle.index[%d]: Failed to decode offset: %v", i, err) |
| 260 | } |
| 261 | length, err := dec.DecodeUint() |
| 262 | if err != nil { |
| 263 | return nil, fmt.Errorf("bundle.index[%d]: Failed to decode length: %v", i, err) |
no test coverage detected