trustlesshttp

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: Apache-2.0, MIT Imports: 8 Imported by: 11

Documentation

Overview

Package trustlesshttp provides a set of simple utilities and constants useful for clients and servers implementing the IPFS Trustless Gateway protocol.

Index

Constants

View Source
const (
	MimeTypeCar                = "application/vnd.ipld.car"            // The only accepted MIME type
	MimeTypeCarVersion         = "1"                                   // We only accept version 1 of the MIME type
	FormatParameterCar         = "car"                                 // The only valid format parameter value
	FilenameExtCar             = ".car"                                // The only valid filename extension
	DefaultIncludeDupes        = true                                  // The default value for an unspecified "dups" parameter. See https://github.com/ipfs/specs/pull/412.
	ResponseAcceptRangesHeader = "bytes"                               // The only valid value for the Accept-Ranges header
	ResponseCacheControlHeader = "public, max-age=29030400, immutable" // Magic cache control values
)

Variables

View Source
var (
	ErrPathNotFound = errors.New("not found")
	ErrBadCid       = errors.New("failed to parse root CID")
)
View Source
var (
	ResponseChunkDelimeter = []byte("0\r\n") // An http/1.1 chunk delimeter, used for specifying an early end to the response

)

Functions

func CheckFormat

func CheckFormat(req *http.Request) (bool, error)

CheckFormat validates that the data being requested is of the type CAR. We do this validation because the IPFS Path Gateway spec allows for additional response formats that the IPFS Trustless Gateway spec does not currently support, so we throw an error in the cases where the request is requesting one the unsupported response formats. IPFS Trustless Gateway only supports returning CAR data.

The spec outlines that the requesting format can be provided via the Accept header or the format query parameter.

IPFS Trustless Gateway only allows the application/vnd.ipld.car Accept header https://specs.ipfs.tech/http-gateways/path-gateway/#accept-request-header

IPFS Trustless Gateway only allows the "car" format query parameter https://specs.ipfs.tech/http-gateways/path-gateway/#format-request-query-parameter

func ParseAccept

func ParseAccept(acceptHeader string) (validAccept bool, includeDupes bool)

ParseAccept validates a request Accept header and returns whether or not duplicate blocks are allowed in the response.

This will operate the same as ParseContentType except that it is less strict with the format specifier, allowing for "application/*" and "*/*" as well as the standard "application/vnd.ipld.car".

func ParseByteRange

func ParseByteRange(req *http.Request) (*trustlessutils.ByteRange, error)

ParseByteRange returns the entity-bytes query parameter if one is set in the query string or nil if one is not set. An error is returned if an entity-bytes query string is not a valid byte range.

func ParseContentType

func ParseContentType(contentTypeHeader string) (validContentType bool, includeDupes bool)

ParseContentType validates a response Content-Type header and returns whether or not duplicate blocks are expected in the response.

This will operate the same as ParseAccept except that it strictly only allows the "application/vnd.ipld.car" Content-Type.

func ParseFilename

func ParseFilename(req *http.Request) (string, error)

ParseFilename returns the filename query parameter or an error if the filename extension is not ".car". Lassie only supports returning CAR data. See https://specs.ipfs.tech/http-gateways/path-gateway/#filename-request-query-parameter

func ParseScope

func ParseScope(req *http.Request) (trustlessutils.DagScope, error)

ParseScope returns the dag-scope query parameter or an error if the dag-scope parameter is not one of the supported values.

func ParseUrlPath

func ParseUrlPath(urlPath string) (cid.Cid, datamodel.Path, error)

ParseUrlPath parses an incoming IPFS Trustless Gateway path of the form /ipfs/<cid>[/<path>] and returns the root CID and the path.

func RequestAcceptHeader

func RequestAcceptHeader(duplicates bool) string

RequestAcceptHeader returns the value for the Accept header for a Trustless Gateway request which will vary depending on whether duplicates are included or not. Otherwise, the header is the same for all requests.

func ResponseContentTypeHeader

func ResponseContentTypeHeader(duplicates bool) string

ResponseContentTypeHeader returns the value for the Content-Type header for a Trustless Gateway response which will vary depending on whether duplicates are included or not. Otherwise, the header is the same for all responses.

Types

This section is empty.

Jump to

Keyboard shortcuts

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