httploader

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnauthorizedRequest = errors.New("unauthorized request")

ErrUnauthorizedRequest unauthorized request error

Functions

This section is empty.

Types

type HTTPLoader

type HTTPLoader struct {
	// The Transport used to request images, default http.DefaultTransport.
	Transport http.RoundTripper

	// ForwardHeaders copy request headers to image request headers
	ForwardHeaders []string

	// OverrideHeaders override image request headers
	OverrideHeaders map[string]string

	// AllowedSources list of host names allowed to load from,
	// supports glob patterns such as *.google.com
	AllowedSources []string

	// Accept set request Accept and validate response Content-Type header
	Accept string

	// MaxAllowedSize maximum bytes allowed for image
	MaxAllowedSize int

	// DefaultScheme default image URL scheme
	DefaultScheme string

	// UserAgent default user agent for image request.
	// Can be overridden by ForwardHeaders and OverrideHeaders
	UserAgent string

	// BlockLoopbackNetworks rejects HTTP connections to loopback network IP addresses.
	BlockLoopbackNetworks bool

	// BlockPrivateNetworks rejects HTTP connections to private network IP addresses.
	BlockPrivateNetworks bool

	// BlockLinkLocalNetworks rejects HTTP connections to link local IP addresses.
	BlockLinkLocalNetworks bool

	// BlockNetworks rejects HTTP connections to a configurable list of networks.
	BlockNetworks []*net.IPNet
	// contains filtered or unexported fields
}

HTTPLoader HTTP Loader implements imagor.Loader interface

func New

func New(options ...Option) *HTTPLoader

New creates HTTPLoader

func (*HTTPLoader) DialControl

func (h *HTTPLoader) DialControl(network string, address string, conn syscall.RawConn) error

DialControl implements a net.Dialer.Control function which is automatically used with the default http.Transport. If the transport is replaced using the WithTransport option it is up to that transport if the control function is used or not.

func (*HTTPLoader) Get

func (h *HTTPLoader) Get(r *http.Request, image string) (*imagor.Blob, error)

Get implements imagor.Loader interface

type Option

type Option func(h *HTTPLoader)

Option HTTPLoader option

func WithAccept

func WithAccept(contentType string) Option

WithAccept with accepted content type option

func WithAllowedSources

func WithAllowedSources(hosts ...string) Option

WithAllowedSources with allowed source hosts option. Accept csv wth glob pattern e.g. *.google.com,*.github.com

func WithBlockLinkLocalNetworks

func WithBlockLinkLocalNetworks(enabled bool) Option

WithBlockLinkLocalNetworks with option to reject HTTP connections to link local IP addresses

func WithBlockLoopbackNetworks

func WithBlockLoopbackNetworks(enabled bool) Option

WithBlockLoopbackNetworks with option to reject HTTP connections to loopback network IP addresses

func WithBlockNetworks

func WithBlockNetworks(networks ...*net.IPNet) Option

WithBlockNetworks with option to reject HTTP connections to a configurable list of networks

func WithBlockPrivateNetworks

func WithBlockPrivateNetworks(enabled bool) Option

WithBlockPrivateNetworks with option to reject HTTP connections to private network IP addresses

func WithDefaultScheme

func WithDefaultScheme(scheme string) Option

WithDefaultScheme with default URL scheme option https or http, if not specified

func WithForwardClientHeaders

func WithForwardClientHeaders(enabled bool) Option

WithForwardClientHeaders with forward browser request headers option

func WithForwardHeaders

func WithForwardHeaders(headers ...string) Option

WithForwardHeaders with forward selected request headers option

func WithInsecureSkipVerifyTransport

func WithInsecureSkipVerifyTransport(enabled bool) Option

WithInsecureSkipVerifyTransport with insecure HTTPs option

func WithMaxAllowedSize

func WithMaxAllowedSize(maxAllowedSize int) Option

WithMaxAllowedSize with maximum allowed size option

func WithOverrideHeader

func WithOverrideHeader(name, value string) Option

WithOverrideHeader with override request header with name value pair option

func WithProxyTransport

func WithProxyTransport(proxyURLs, hosts string) Option

WithProxyTransport with random proxy rotation option for selected proxy URLs

func WithTransport

func WithTransport(transport http.RoundTripper) Option

WithTransport with custom http.RoundTripper transport option

func WithUserAgent

func WithUserAgent(userAgent string) Option

WithUserAgent with custom user agent option

Jump to

Keyboard shortcuts

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