fshttp

package
v1.73.1-bclone Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2025 License: MIT Imports: 26 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 LoadKeyPair

func LoadKeyPair(certFile, keyFile, password string) (cert tls.Certificate, err error)

LoadKeyPair loads a TLS certificate and private key from PEM-encoded files, with extended support for encrypted private keys.

This function is designed as a robust replacement for tls.X509KeyPair, providing the same core functionality but adding support for password-protected private keys.

The certificate file (certFile) must contain one or more PEM-encoded certificates. The first certificate is treated as the leaf certificate, and any subsequent certificates are treated as its chain.

The key file (keyFile) must contain a PEM-encoded private key. Supported formats are:

  • Unencrypted PKCS#1 ("BEGIN RSA PRIVATE KEY")
  • Unencrypted PKCS#8 ("BEGIN PRIVATE KEY")
  • Encrypted PKCS#8 ("BEGIN ENCRYPTED PRIVATE KEY")
  • Legacy PEM encryption (e.g., DEK-Info headers), which are automatically detected.

The password parameter is used to decrypt the private key. If the key is not encrypted, this parameter is ignored and can be an empty string. The password should be an obscured string.

On success, it returns a fully populated tls.Certificate struct, including the Leaf certificate field.

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

func NewTransport(ctx context.Context) *Transport

NewTransport returns an http.RoundTripper with the correct timeouts

func NewTransportCustom

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

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 (*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

Jump to

Keyboard shortcuts

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