Documentation
¶
Overview ¶
Package discover finds a station's manifest from a homepage or a stream URL (SPECIFICATION.md section 3) and applies the verification rule of section 4.3, with the fetching limits of section 10.2.
Index ¶
Constants ¶
const ( DefaultTimeout = 10 * time.Second DefaultMaxBody = manifest.MaxManifestBytes DefaultMaxRedirects = 5 )
Defaults from section 10.2.
const ( // ManifestRel is the link relation of the HTTP Link header (section 3, item 3). ManifestRel = "radio-manifest" // ManifestType is the media type of the HTML link (section 3, item 2). ManifestType = "application/radio-manifest+json" // WellKnownPath is the well-known address (section 3, item 1). WellKnownPath = "/.well-known/radio-manifest.json" )
Variables ¶
var ( ErrNoManifest = errors.New("no manifest found") ErrTooLarge = errors.New("response body exceeds the size limit") ErrTooManyRedirects = errors.New("too many redirects") ErrInsecureRedirect = errors.New("redirect to http is not allowed in the production tier") ErrInsecureURL = errors.New("address must use https in the production tier") ErrDevelopmentAddress = errors.New("development-tier address refused (section 10.2)") ErrGUIDMismatch = errors.New("guid differs between the fetched copy and the manifestUrl copy (section 4.2)") ErrBadScheme = errors.New("only http and https addresses are supported") )
Errors returned by discovery.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client performs discovery.
func (*Client) Discover ¶
Discover accepts a homepage or a stream URL. It probes the URL with HEAD: a stream-like answer (audio or playlist content type, icy headers, or a radio-manifest Link header) takes the stream path, anything else the homepage path. The call is bounded by Config.Timeout.
func (*Client) FromHomepage ¶
FromHomepage discovers a manifest from a homepage URL: the HTML link first (it wins when the two disagree, section 3), then the well-known address.
func (*Client) FromStream ¶
FromStream discovers a manifest from a stream URL: the HTTP Link header (HEAD, then a one-byte ranged GET whose body is never read), then an icy-url header taken as a homepage. The stream body is never downloaded.
type Config ¶
type Config struct {
// HTTPClient is optional; its Transport is used, its CheckRedirect and
// Timeout are replaced. When nil a client with a guarded dialer is built.
HTTPClient *http.Client
// Timeout bounds one whole discovery call (default 10 s).
Timeout time.Duration
// MaxBody is the largest body read (default 256 KiB).
MaxBody int64
// MaxRedirects is the most redirects followed (default 5).
MaxRedirects int
// Development configures the client for development: http is allowed for
// development hosts and development addresses may be contacted.
Development bool
// AllowPrivate lets the client contact development-tier addresses without
// relaxing the https rules; intended for tests with TLS servers on loopback.
AllowPrivate bool
// UserAgent defaults to "radio2-discover".
UserAgent string
}
Config controls a Client. The zero value is the production tier with the limits of section 10.2.
type Result ¶
type Result struct {
Input string
Kind string // "homepage" or "stream"
ManifestURL string // the manifest's own manifestUrl once fetched
FoundAt string // where the manifest address was first found
Via Via
// ICYHomepage is the homepage taken from an icy-url header, when used.
ICYHomepage string
Manifest *manifest.Manifest
// Problems are validation findings on the fetched manifest (informational:
// a consumer ignores unknown members, so they do not stop discovery).
Problems []manifest.Problem
Verdict
}
Result is the outcome of a discovery.
type StatusError ¶
StatusError is returned for a non-200 answer. A 503 or a network failure is not removal (section 4.4); 404 and 410 are.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
func (*StatusError) Removed ¶
func (e *StatusError) Removed() bool
Removed reports whether the status means the station no longer publishes at that address (404 or 410).
type Verdict ¶
type Verdict struct {
// OriginVerified: manifestUrl is the well-known address on the homepage
// origin, or the homepage's HTML link names exactly manifestUrl.
OriginVerified bool
// Verified: OriginVerified, https for homepage and manifestUrl, and a
// production-tier manifest. Only a verified manifest may be listed publicly.
Verified bool
// By is "well-known" or "html-link" when OriginVerified.
By string
// Reasons explain why a manifest is not verified.
Reasons []string
}
Verdict is the outcome of the verification rule of section 4.3.