fshttp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package fshttp contains the common http parts of the config, Transport and Client

Index

Constants

This section is empty.

Variables

View Source
var DefaultMetrics = (*Metrics)(nil)

DefaultMetrics specifies metrics used for new Transports.

View Source
var (

	// UnixSocketConfig describes the option to configure the path to a unix domain socket to connect to
	UnixSocketConfig = fs.Option{
		Name:     "unix_socket",
		Help:     "Path to a unix domain socket to dial to, instead of opening a TCP connection directly",
		Advanced: true,
		Default:  "",
	}
)

Functions

func NewClient

func NewClient(ctx context.Context) *http.Client

NewClient returns an http.Client with the correct timeouts

func NewClientCustom

func NewClientCustom(ctx context.Context, customize func(*http.Transport)) *http.Client

NewClientCustom returns an http.Client with the correct timeouts. It allows customizing the transport, using NewTransportCustom.

func NewClientWithUnixSocket

func NewClientWithUnixSocket(ctx context.Context, path string) *http.Client

NewClientWithUnixSocket returns an http.Client with the correct timeout. It internally uses NewClientCustom with a custom dialer connecting to the specified unix domain socket.

func NewTransport

func NewTransport(ctx context.Context) http.RoundTripper

NewTransport returns an http.RoundTripper with the correct timeouts

func NewTransportCustom

func NewTransportCustom(ctx context.Context, customize func(*http.Transport)) http.RoundTripper

NewTransportCustom returns an http.RoundTripper with the correct timeouts. The customize function is called if set to give the caller an opportunity to customize any defaults in the Transport.

func ResetTransport

func ResetTransport()

ResetTransport resets the existing transport, allowing it to take new settings. Should only be used for testing.

Types

type Dialer

type Dialer struct {
	net.Dialer
	// contains filtered or unexported fields
}

Dialer structure contains default dialer and timeout, tclass support

func NewDialer

func NewDialer(ctx context.Context) *Dialer

NewDialer creates a Dialer structure with Timeout, Keepalive, LocalAddr and DSCP set from rclone flags.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial connects to the network address.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext connects to the network address using the provided context.

type Metrics

type Metrics struct {
	StatusCode *prometheus.CounterVec
}

Metrics provide Transport HTTP level metrics.

func NewMetrics

func NewMetrics(namespace string) *Metrics

NewMetrics creates a new metrics instance, the instance shall be assigned to DefaultMetrics before any processing takes place.

func (*Metrics) Collectors

func (m *Metrics) Collectors() []prometheus.Collector

Collectors returns all prometheus metrics as collectors for registration.

type Transport

type Transport struct {
	*http.Transport
	// contains filtered or unexported fields
}

Transport is our http Transport which wraps an http.Transport * Sets the User Agent * Does logging * Updates metrics

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error)

RoundTrip implements the RoundTripper interface.

func (*Transport) SetRequestFilter

func (t *Transport) SetRequestFilter(f func(req *http.Request))

SetRequestFilter sets a filter to be used on each request

func (*Transport) SetUserAgent

func (t *Transport) SetUserAgent(s string)

Jump to

Keyboard shortcuts

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