reportingapi

package
v0.0.0-...-f115076 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package reportingapi is an implementation of the Report-To header described in https://www.w3.org/TR/reporting/#header.

It allows for setting reporting groups to use in conjuction with COOP and CSP.

Index

Constants

View Source
const DefaultMaxAge = 7 * 24 * 60 * 60

DefaultMaxAge is used as default cache duration for report groups and will make them last 7 days.

View Source
const ReportToHeaderKey = "Report-To"

ReportToHeaderKey is the HTTP header key for the Reporting API.

Variables

This section is empty.

Functions

This section is empty.

Types

type Endpoint

type Endpoint struct {
	// URL defines the location of the endpoint.
	// The URL that the member's value represents MUST be potentially trustworthy. Non-secure endpoints will be ignored.
	URL string `json:"url"`
	// Priority defines which failover class the endpoint belongs to.
	Priority uint `json:"priority,omitempty"`
	// Weight defines load balancing for the failover class that the endpoint belongs to.
	Weight uint `json:"weight,omitempty"`
}

Endpoint is the Go representation of the endpoints values as specified in https://www.w3.org/TR/reporting/#endpoints-member

type Group

type Group struct {
	// Name associates a name with the set of endpoints.
	// This is serialized as the "group" field in the Report-To header.
	// If left empty, the endpoint group will be given the name "default".
	Name string `json:"group,omitempty"`
	// IncludeSubdomains enables this endpoint group for all subdomains of the current origin’s host.
	IncludeSubdomains bool `json:"include_subdomains,omitempty"`
	// MaxAge defines the endpoint group’s lifetime, as a non-negative integer number of seconds.
	// A value of 0 will cause the endpoint group to be removed from the user agent’s reporting cache.
	MaxAge uint `json:"max_age"`
	// Endpoints is the list of endpoints that belong to this endpoint group.
	Endpoints []Endpoint `json:"endpoints"`
}

Group is the Go representation of the Report-To header values as specified in https://www.w3.org/TR/reporting/#header.

func NewGroup

func NewGroup(name string, url string, otherUrls ...string) Group

NewGroup creates a new Group with MaxAge set to DefaultMaxage and all optional values set to their default values.

type Interceptor

type Interceptor struct {
	// contains filtered or unexported fields
}

Interceptor is the interceptor for the Report-To header.

func NewInterceptor

func NewInterceptor(groups ...Group) Interceptor

NewInterceptor instantiates a new Interceptor for the given groups.

func (Interceptor) Before

Before adds all the configured Report-To header values as separate headers.

func (Interceptor) Commit

Commit is a no-op, required to satisfy the safehttp.Interceptor interface.

func (Interceptor) Match

Match returns false since there are no supported configurations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL