source

package
v2.0.2-rc.9 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LastModified    = "X-Dragonfly-Last-Modified"
	IfModifiedSince = "X-Dragonfly-If-Modified-Since"
	ETag            = "X-Dragonfly-ETag"
	IfNoneMatch     = "X-Dragonfly-If-None-Match"
	Range           = "X-Dragonfly-Range" // startIndex-endIndex
)
View Source
const LastModifiedLayout = "Mon, 02 Jan 2006 15:04:05 GMT"
View Source
const (
	UnknownSourceFileLen = -2
)

Variables

View Source
var (
	// ErrResourceNotReachable represents the url resource is a not reachable.
	ErrResourceNotReachable = errors.New("resource is not reachable")

	// ErrNoClientFound represents no source client to resolve url
	ErrNoClientFound = errors.New("no source client found")

	// ErrClientNotSupportList represents the source client not support list action
	ErrClientNotSupportList = errors.New("source client not support list")
)

Functions

func CanonicalHeaderKey added in v2.0.2

func CanonicalHeaderKey(s string) string

func CheckResponseCode added in v2.0.2

func CheckResponseCode(respCode int, allowed []int) error

CheckResponseCode returns UnexpectedStatusError if the given response code is not one of the allowed status codes; otherwise nil.

func GetContentLength

func GetContentLength(request *Request) (int64, error)

func GetLastModified added in v2.0.2

func GetLastModified(request *Request) (int64, error)

func IsExpired

func IsExpired(request *Request, info *ExpireInfo) (bool, error)

func IsNoClientFoundError added in v2.0.2

func IsNoClientFoundError(err error) bool

func IsResourceNotReachableError added in v2.0.2

func IsResourceNotReachableError(err error) bool

func IsSupportRange

func IsSupportRange(request *Request) (bool, error)

func List added in v2.0.2

func List(request *Request) ([]*url.URL, error)

func Register

func Register(scheme string, resourceClient ResourceClient, adaptor requestAdapter, hooks ...Hook) error

func RequestEq added in v2.0.2

func RequestEq(url string) gomock.Matcher

RequestEq for gomock

func UnRegister

func UnRegister(scheme string)

func UpdatePluginDir added in v2.0.2

func UpdatePluginDir(pluginDir string)

func WithContentLength added in v2.0.2

func WithContentLength(length int64) func(*Response)

func WithExpireInfo added in v2.0.2

func WithExpireInfo(info ExpireInfo) func(*Response)

func WithHeader added in v2.0.2

func WithHeader(header map[string]string) func(*Response)

func WithStatus added in v2.0.2

func WithStatus(code int, status string) func(*Response)

Types

type ClientManager

type ClientManager interface {
	// Register a source client with scheme
	Register(scheme string, resourceClient ResourceClient, adapter requestAdapter, hook ...Hook) error

	// UnRegister a source client from manager
	UnRegister(scheme string)

	// GetClient a source client by scheme
	GetClient(scheme string, options ...Option) (ResourceClient, bool)
}

func NewManager

func NewManager() ClientManager

type ExpireInfo added in v2.0.2

type ExpireInfo struct {
	LastModified string // Mon, 02 Jan 2006 15:04:05 GMT
	ETag         string
}
type Header map[string][]string

A Header represents the key-value pairs in a Dragonfly source header.

The keys should be in canonical form, as returned by CanonicalHeaderKey.

func (Header) Add added in v2.0.2

func (h Header) Add(key, value string)

Add adds the key, value pair to the header. It appends to any existing values associated with key. The key is case insensitive; it is canonicalized by CanonicalHeaderKey.

func (Header) Clone added in v2.0.2

func (h Header) Clone() Header

Clone returns a copy of h or nil if h is nil.

func (Header) Del added in v2.0.2

func (h Header) Del(key string)

Del deletes the values associated with key. The key is case insensitive; it is canonicalized by CanonicalHeaderKey.

func (Header) Get added in v2.0.2

func (h Header) Get(key string) string

Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "". It is case insensitive; textproto.CanonicalMIMEHeaderKey is used to canonicalize the provided key. To use non-canonical keys, access the map directly.

func (Header) Set added in v2.0.2

func (h Header) Set(key, value string)

Set sets the header entries associated with key to the single element value. It replaces any existing values associated with key. The key is case insensitive; it is canonicalized by textproto.CanonicalMIMEHeaderKey. To use non-canonical keys, assign to the map directly.

func (Header) Values added in v2.0.2

func (h Header) Values(key string) []string

Values returns all values associated with the given key. It is case insensitive; textproto.CanonicalMIMEHeaderKey is used to canonicalize the provided key. To use non-canonical keys, access the map directly. The returned slice is not a copy.

type Hook added in v2.0.2

type Hook interface {
	BeforeRequest(request *Request) error
	AfterResponse(response *Response) error
}

Hook TODO hook

type Option added in v2.0.2

type Option func(c *clientManager)

type Request added in v2.0.2

type Request struct {
	URL    *url.URL
	Header Header
	// contains filtered or unexported fields
}

func NewRequest added in v2.0.2

func NewRequest(rawURL string) (*Request, error)

func NewRequestWithContext added in v2.0.2

func NewRequestWithContext(ctx context.Context, rawURL string, header map[string]string) (*Request, error)

func NewRequestWithHeader added in v2.0.2

func NewRequestWithHeader(rawURL string, header map[string]string) (*Request, error)

func (*Request) Clone added in v2.0.2

func (r *Request) Clone(ctx context.Context) *Request

Clone returns a deep copy of r with its context changed to ctx. The provided ctx must be non-nil.

For an outgoing client request, the context controls the entire lifetime of a request and its response: obtaining a connection, sending the request, and reading the response headers and body.

func (*Request) Context added in v2.0.2

func (r *Request) Context() context.Context

Context returns the request's context. To change the context, use WithContext.

The returned context is always non-nil; it defaults to the background context.

For outgoing client requests, the context controls cancellation.

For incoming server requests, the context is canceled when the client's connection closes, the request is canceled (with HTTP/2), or when the ServeHTTP method returns.

func (*Request) WithContext added in v2.0.2

func (r *Request) WithContext(ctx context.Context) *Request

WithContext returns a shallow copy of r with its context changed to ctx. The provided ctx must be non-nil.

For outgoing client request, the context controls the entire lifetime of a request and its response: obtaining a connection, sending the request, and reading the response headers and body.

To create a new request with a context, use NewRequestWithContext. To change the context of a request, such as an incoming request you want to modify before sending back out, use Request.Clone. Between those two uses, it's rare to need WithContext.

type ResourceClient

type ResourceClient interface {
	// GetContentLength get length of resource content
	// return source.UnknownSourceFileLen if response status is not StatusOK and StatusPartialContent
	GetContentLength(request *Request) (int64, error)

	// IsSupportRange checks if resource supports breakpoint continuation
	// return false if response status is not StatusPartialContent
	IsSupportRange(request *Request) (bool, error)

	// IsExpired checks if a resource received or stored is the same.
	// return false and non-nil err to prevent the source from exploding if
	// fails to get the result, it is considered that the source has not expired
	IsExpired(request *Request, info *ExpireInfo) (bool, error)

	// Download downloads from source
	Download(request *Request) (*Response, error)

	// GetLastModified gets last modified timestamp milliseconds of resource
	GetLastModified(request *Request) (int64, error)
}

ResourceClient defines the API interface to interact with source.

func LoadPlugin

func LoadPlugin(dir, scheme string) (ResourceClient, error)

type ResourceLister added in v2.0.2

type ResourceLister interface {
	List(request *Request) (urls []*url.URL, err error)
}

ResourceLister defines the interface to list all downloadable resources in request url

type Response added in v2.0.2

type Response struct {
	Status        string
	StatusCode    int
	Header        Header
	Body          io.ReadCloser
	ContentLength int64
}

func Download

func Download(request *Request) (*Response, error)

func NewResponse added in v2.0.2

func NewResponse(rc io.ReadCloser, opts ...func(*Response)) *Response

func (*Response) ExpireInfo added in v2.0.2

func (resp *Response) ExpireInfo() ExpireInfo

type UnexpectedStatusCodeError added in v2.0.2

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

UnexpectedStatusCodeError is returned when a source responds with neither an error nor with a status code indicating success.

func (UnexpectedStatusCodeError) Error added in v2.0.2

Error implements interface error

func (UnexpectedStatusCodeError) Got added in v2.0.2

Got is the actual status code returned by source.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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