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
- Variables
- func CheckFormat(req *http.Request) (bool, error)
- func ParseAccept(acceptHeader string) (validAccept bool, includeDupes bool)
- func ParseByteRange(req *http.Request) (*trustlessutils.ByteRange, error)
- func ParseContentType(contentTypeHeader string) (validContentType bool, includeDupes bool)
- func ParseFilename(req *http.Request) (string, error)
- func ParseScope(req *http.Request) (trustlessutils.DagScope, error)
- func ParseUrlPath(urlPath string) (cid.Cid, datamodel.Path, error)
- func RequestAcceptHeader(duplicates bool) string
- func ResponseContentTypeHeader(duplicates bool) string
Constants ¶
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 ¶
var ( ErrPathNotFound = errors.New("not found") ErrBadCid = errors.New("failed to parse root CID") )
var (
ResponseChunkDelimeter = []byte("0\r\n") // An http/1.1 chunk delimeter, used for specifying an early end to the response
)
Functions ¶
func CheckFormat ¶
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 ¶
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 ¶
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 ¶
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 ¶
ParseUrlPath parses an incoming IPFS Trustless Gateway path of the form /ipfs/<cid>[/<path>] and returns the root CID and the path.
func RequestAcceptHeader ¶
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 ¶
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.