httpserver

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: Apache-2.0, MIT Imports: 22 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	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 = "none"                                // We currently don't accept range requests
	ResponseCacheControlHeader = "public, max-age=29030400, immutable" // Magic cache control values
	ResponseChunkDelimeter     = []byte("0\r\n")                       // An http/1.1 chunk delimeter, used for specifying an early end to the response
	ResponseContentTypeHeader  = fmt.Sprintf("%s; version=%s", MimeTypeCar, MimeTypeCarVersion)
)

Functions

func CheckFormat added in v0.13.0

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 http gateway path spec allows for additional response formats that Lassie does not currently support, so we throw an error in the cases where the request is requesting one of Lassie's unsupported response formats. Lassie only supports returning CAR data.

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

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

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

func ParseAccept added in v0.13.0

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

ParseAccept validates that the request Accept header is of the type CAR and returns whether or not duplicate blocks are allowed in the response via IPIP-412: https://github.com/ipfs/specs/pull/412.

func ParseFilename added in v0.13.0

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 added in v0.13.0

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

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

Types

type HttpServer

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

HttpServer is a Lassie server for fetching data from the network via HTTP

func NewHttpServer

func NewHttpServer(ctx context.Context, lassie *lassie.Lassie, cfg HttpServerConfig) (*HttpServer, error)

NewHttpServer creates a new HttpServer

func (HttpServer) Addr

func (s HttpServer) Addr() string

Addr returns the listening address of the server

func (*HttpServer) Close

func (s *HttpServer) Close() error

Close shutsdown the server and cancels the server context

func (*HttpServer) Start

func (s *HttpServer) Start() error

Start starts the http server, returning an error if the server failed to start

type HttpServerConfig added in v0.4.4

type HttpServerConfig struct {
	Address             string
	Port                uint
	TempDir             string
	MaxBlocksPerRequest uint64
	AccessToken         string
}

Jump to

Keyboard shortcuts

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