validity

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package validity handles the validity data of signed exchanges. It only defines validity URLs at the moment though.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type URLRule

type URLRule interface {
	// Apply returns the validity URL of a resource. physurl is the physical
	// URL of the resource; resp is the HTTP response; vp is the period the
	// signed exchange will be valid for. The physical URL is typically equal
	// to the request URL but different in some cases; see package urlrewrite
	// for more details.
	//
	// Note implementations can retrieve the request URL via resp.Request.URL.
	Apply(physurl *url.URL, resp *exchange.Response, vp exchange.ValidPeriod) (*url.URL, error)
}

URLRule decides the validity URL of a resource.

var DefaultURLRule URLRule = AppendExtDotLastModified(".validity")

DefaultURLRule is the default rule used by webpackager.Packager.

func AppendExtDotExchangeDate

func AppendExtDotExchangeDate(ext string) URLRule

AppendExtDotExchangeDate is like AppendExtDotLastModified but always uses vp.Date instead of the last modified time.

func AppendExtDotLastModified

func AppendExtDotLastModified(ext string) URLRule

AppendExtDotLastModified generates the validity URL by appending ext and the resource's last modified time. For example:

https://example.com/index.html

would receive a validity URL that looks like:

https://example.com/index.html.validity.1561984496

ext usually starts with a dot ("."). AppendExtDotExchangeDate does not insert it automatically. ext is thus ".validity" rather than "validity" in the example above.

The last modified time is taken from the Last-Modified header field in the HTTP response and represented in UNIX time. If the Last-Modified is missing or unparsable, AppendExtDotLastModified uses the date value of the signed exchange signature (vp.Date).

The AppendExtDotLastModified rule does not support physurl that looks like a directory (e.g. has Path ending with a slash). Apply returns an error for such physurl. Note you can use urlrewrite.IndexRule to ensure physurl to always have a filename.

The AppendExtDotLastModified rule ignores Query and Fragment in physurl. The validity URLs will always have empty Query and Fragment.

func FixedURL

func FixedURL(url *url.URL) URLRule

FixedURL uses url as the validity URL for all resources. It is useful, for example, if you plan to provide empty validity data (consisting of a single byte 0xa0) for all signed exchanges and serve it on a single URL.

url can be relative, in which case the validity URL is resolved relative from the physical URL.

Jump to

Keyboard shortcuts

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