Documentation
¶
Overview ¶
Package feed fetches the bentoo notices feed over HTTPS with ETag revalidation, a body size cap and a request deadline. It is a library package: it returns errors carrying the URL, the status and the byte count, and leaves logging to its caller.
Index ¶
Constants ¶
const ( // MaxBodyBytes is the largest feed body accepted. MaxBodyBytes int64 = 1 << 20 // Timeout bounds a whole fetch made with the default client. Timeout = 30 * time.Second )
Variables ¶
var ( // ErrInsecureURL is returned by New for a feed URL that is not https. ErrInsecureURL = errors.New("feed URL is not https") // ErrTooLarge is returned by Fetch when the body exceeds MaxBodyBytes. ErrTooLarge = errors.New("feed body exceeds 1 MiB") )
Functions ¶
func DefaultClient ¶
DefaultClient returns the client New uses when given none.
func DefaultUserAgent ¶
func DefaultUserAgent() string
DefaultUserAgent returns "bentoo-tray/<tray version>", the version the tray reports for itself rather than the bentoolkit release it ships in.
Types ¶
type Fetcher ¶
type Fetcher struct {
// contains filtered or unexported fields
}
Fetcher performs conditional GETs of one feed URL.
func New ¶
New returns a Fetcher for rawURL. A URL that is not an absolute https URL with a host is refused with ErrInsecureURL naming it. A nil client is replaced by the default: a 30 s timeout, the shared transport and the credential-safe redirect policy. An empty userAgent is replaced by "bentoo-tray/<version>".
func (*Fetcher) Fetch ¶
Fetch GETs the feed, sending etag as If-None-Match when it is not empty. A 304 yields a Result with NotModified set and no feed; a 200 yields the parsed feed and the response's ETag. Any other status is a *StatusError; a body past MaxBodyBytes is ErrTooLarge; a 200 whose body is not a valid feed is an error wrapping notices.ErrInvalidFeed. Every error names the URL, and every response, failed or not, reports Status and Bytes.
type Result ¶
Result is the outcome of a fetch that received a response. Status and Bytes are set whenever a response arrived, including alongside an error, so the caller can log them on every outcome.
type StatusError ¶
StatusError reports a response whose status is neither 200 nor 304. Bytes is the size of the body read, and RetryAfter the server's Retry-After header as a duration (zero when absent, unparsable or in the past).
func (*StatusError) Error ¶
func (e *StatusError) Error() string