httploader

package
v1.4.11 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 16 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 AllowedSource added in v1.4.5

type AllowedSource struct {
	HostPattern string
	URLRegex    *regexp.Regexp
}

AllowedSource represents a source the HTTPLoader is allowed to load from. It supports host glob patterns such as *.google.com and a full URL regex.

func NewHostPatternAllowedSource added in v1.4.5

func NewHostPatternAllowedSource(pattern string) AllowedSource

NewHostPatternAllowedSource creates a new AllowedSource from the host glob pattern

func NewRegexpAllowedSource added in v1.4.5

func NewRegexpAllowedSource(pattern string) (AllowedSource, error)

NewRegexpAllowedSource creates a new AllowedSource from the regex pattern

func (AllowedSource) Match added in v1.4.5

func (s AllowedSource) Match(u *url.URL) bool

Match checks if the url matches the AllowedSource

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

	// OverrideResponseHeaders override image response header from HTTP Loader response
	OverrideResponseHeaders []string

	// AllowedSources list of sources allowed to load from
	AllowedSources []AllowedSource

	// 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

	// BaseURL base URL for HTTP loader
	BaseURL *url.URL
	// 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 added in v1.2.4

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

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

func WithAccept(contentType string) Option

WithAccept with accepted content type option

func WithAllowedSourceRegexps added in v1.4.5

func WithAllowedSourceRegexps(patterns ...string) 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 WithBaseURL added in v1.4.1

func WithBaseURL(baseURL string) Option

WithBaseURL with base URL option for valid URL string

func WithBlockLinkLocalNetworks added in v1.2.4

func WithBlockLinkLocalNetworks(enabled bool) Option

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

func WithBlockLoopbackNetworks added in v1.2.4

func WithBlockLoopbackNetworks(enabled bool) Option

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

func WithBlockNetworks added in v1.2.4

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

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

func WithBlockPrivateNetworks added in v1.2.4

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

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 WithOverrideResponseHeaders added in v1.4.11

func WithOverrideResponseHeaders(headers ...string) Option

WithOverrideResponseHeaders with override selected response headers option

func WithProxyTransport added in v0.7.3

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