httploader

package
v1.4.13 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 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

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

func NewHostPatternAllowedSource(pattern string) AllowedSource

NewHostPatternAllowedSource creates a new AllowedSource from the host glob pattern

func NewRegexpAllowedSource

func NewRegexpAllowedSource(pattern string) (AllowedSource, error)

NewRegexpAllowedSource creates a new AllowedSource from the regex pattern

func (AllowedSource) Match

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

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 WithAllowedSourceRegexps

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

func WithBaseURL(baseURL string) Option

WithBaseURL with base URL option for valid URL string

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 WithOverrideResponseHeaders

func WithOverrideResponseHeaders(headers ...string) Option

WithOverrideResponseHeaders with override selected response headers 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