httpservice

package
v5.9.2-rc1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2019 License: AGPL-3.0, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConnectTimeout = 3 * time.Second
	RequestTimeout = 30 * time.Second
)

Variables

View Source
var AddressForbidden error = errors.New("address forbidden, you may need to set AllowedUntrustedInternalConnections to allow an integration access to your internal network")

Functions

func IsOwnIP

func IsOwnIP(ip net.IP) (bool, error)

IsOwnIP handles the special case that a request might be made to the public IP of the host which on Linux is routed directly via the loopback IP to any listening sockets, effectively bypassing host-based firewalls such as firewalld

func IsReservedIP

func IsReservedIP(ip net.IP) bool

IsReservedIP checks whether the target IP belongs to reserved IP address ranges to avoid SSRF attacks to the internal network of the Mattermost server

func NewTransport

func NewTransport(enableInsecureConnections bool, allowHost func(host string) bool, allowIP func(ip net.IP) bool) http.RoundTripper

Types

type DialContextFunction

type DialContextFunction func(ctx context.Context, network, addr string) (net.Conn, error)

type HTTPService

type HTTPService interface {
	// MakeClient returns an http client constructed with a RoundTripper as returned by MakeTransport.
	MakeClient(trustURLs bool) *http.Client

	// MakeTransport returns a RoundTripper that is suitable for making requests to external resources. The default
	// implementation provides:
	// - A shorter timeout for dial and TLS handshake (defined as constant "ConnectTimeout")
	// - A timeout for end-to-end requests
	// - A Mattermost-specific user agent header
	// - Additional security for untrusted and insecure connections
	MakeTransport(trustURLs bool) http.RoundTripper
}

HTTPService wraps the functionality for making http requests to provide some improvements to the default client behaviour.

func MakeHTTPService

func MakeHTTPService(configService configservice.ConfigService) HTTPService

type HTTPServiceImpl

type HTTPServiceImpl struct {
	RequestTimeout time.Duration
	// contains filtered or unexported fields
}

func (*HTTPServiceImpl) MakeClient

func (h *HTTPServiceImpl) MakeClient(trustURLs bool) *http.Client

func (*HTTPServiceImpl) MakeTransport

func (h *HTTPServiceImpl) MakeTransport(trustURLs bool) http.RoundTripper

type MattermostTransport

type MattermostTransport struct {
	// Transport is the underlying http.RoundTripper that is actually used to make the request
	Transport http.RoundTripper
}

MattermostTransport is an implementation of http.RoundTripper that ensures each request contains a custom user agent string to indicate that the request is coming from a Mattermost instance.

func (*MattermostTransport) RoundTrip

func (t *MattermostTransport) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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