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

Function parsePrimarySection

go/bundle/decoder.go:305–320  ·  view source on GitHub ↗

The "primary" section records a single URL identifying the primary URL of the bundle. The URL MUST refer to a resource with representations contained in the bundle itself.

(sectionContents []byte)

Source from the content-addressed store, hash-verified

303
304// The "primary" section records a single URL identifying the primary URL of the bundle. The URL MUST refer to a resource with representations contained in the bundle itself.
305func parsePrimarySection(sectionContents []byte) (*url.URL, error) {
306 dec := cbor.NewDecoder(bytes.NewBuffer(sectionContents))
307 urlString, err := dec.DecodeTextString()
308 if err != nil {
309 return nil, fmt.Errorf("bundle: failed to parse primary section: %v", err)
310 }
311 primaryURL, err := url.Parse(urlString)
312 // If url is a failure, its fragment is not null, or it includes credentials, return an error.
313 if err != nil {
314 return nil, fmt.Errorf("bundle: failed to parse primary URL (%s): %v", urlString, err)
315 }
316 if !primaryURL.IsAbs() || primaryURL.Fragment != "" || primaryURL.User != nil {
317 return nil, fmt.Errorf("bundle: primary URL (%s) must be an absolute url without fragment or credentials.", urlString)
318 }
319 return primaryURL, nil
320}
321
322// https://wpack-wg.github.io/bundled-responses/draft-ietf-wpack-bundled-responses.html#manifest-section
323func parseManifestSection(sectionContents []byte) (*url.URL, error) {

Callers 1

loadMetadataFunction · 0.85

Calls 2

DecodeTextStringMethod · 0.95
NewDecoderFunction · 0.92

Tested by

no test coverage detected