httpclient

package
v2.0.0-...-83f77b2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package httpclient provides HTTP client configuration for SFTPGo hooks

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(url string) (*http.Response, error)

Get issues a GET to the specified URL

func GetHTTPClient

func GetHTTPClient() *http.Client

GetHTTPClient returns a new HTTP client with the configured parameters

func GetRetraybleHTTPClient

func GetRetraybleHTTPClient() *retryablehttp.Client

GetRetraybleHTTPClient returns an HTTP client that retry a request on error. It uses the configured retry parameters

func Post

func Post(url string, contentType string, body io.Reader) (*http.Response, error)

Post issues a POST to the specified URL

func RetryableGet

func RetryableGet(url string) (*http.Response, error)

RetryableGet issues a GET to the specified URL using the retryable client

func RetryablePost

func RetryablePost(url string, contentType string, body io.Reader) (*http.Response, error)

RetryablePost issues a POST to the specified URL using the retryable client

Types

type Config

type Config struct {
	// Timeout specifies a time limit, in seconds, for a request
	Timeout float64 `json:"timeout" mapstructure:"timeout"`
	// RetryWaitMin defines the minimum waiting time between attempts in seconds
	RetryWaitMin int `json:"retry_wait_min" mapstructure:"retry_wait_min"`
	// RetryWaitMax defines the minimum waiting time between attempts in seconds
	RetryWaitMax int `json:"retry_wait_max" mapstructure:"retry_wait_max"`
	// RetryMax defines the maximum number of attempts
	RetryMax int `json:"retry_max" mapstructure:"retry_max"`
	// CACertificates defines extra CA certificates to trust.
	// The paths can be absolute or relative to the config dir.
	// Adding trusted CA certificates is a convenient way to use self-signed
	// certificates without defeating the purpose of using TLS
	CACertificates []string `json:"ca_certificates" mapstructure:"ca_certificates"`
	// Certificates defines the certificates to use for mutual TLS
	Certificates []TLSKeyPair `json:"certificates" mapstructure:"certificates"`
	// if enabled the HTTP client accepts any TLS certificate presented by
	// the server and any host name in that certificate.
	// In this mode, TLS is susceptible to man-in-the-middle attacks.
	// This should be used only for testing.
	SkipTLSVerify bool `json:"skip_tls_verify" mapstructure:"skip_tls_verify"`
	// Headers defines a list of http headers to add to each request
	Headers []Header `json:"headers" mapstructure:"headers"`
	// contains filtered or unexported fields
}

Config defines the configuration for HTTP clients. HTTP clients are used for executing hooks such as the ones used for custom actions, external authentication and pre-login user modifications

func (*Config) Initialize

func (c *Config) Initialize(configDir string) error

Initialize configures HTTP clients

type Header struct {
	Key   string `json:"key" mapstructure:"key"`
	Value string `json:"value" mapstructure:"value"`
	URL   string `json:"url" mapstructure:"url"`
}

Header defines an HTTP header. If the URL is not empty, the header is added only if the requested URL starts with the one specified

type TLSKeyPair

type TLSKeyPair struct {
	Cert string `json:"cert" mapstructure:"cert"`
	Key  string `json:"key" mapstructure:"key"`
}

TLSKeyPair defines the paths for a TLS key pair

Jump to

Keyboard shortcuts

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