client

package
v1.128.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ClientTLS is the parsed block and its reloading certificate; nil when
	// unconfigured or when the block has enabled=false.
	ClientTLS *utilsTLS.DXClientTLS
)

The process-wide outbound TLS state, set once at startup by LoadFromConfiguration from the "http-client" configuration's tls block and read by every client this package or the api package builds. Both stay nil when there is no such block, and a nil Transport on an http.Client is http.DefaultTransport -- exactly the client every release before this one built -- so a consumer that never writes the block sees no change at all.

Like HTTPClientDoTimeout in the api package, these are assigned before any request is made and are not safe to change while requests are in flight.

Functions

func ApplyTLSConfiguration

func ApplyTLSConfiguration(tlsKV utils.JSON) error

ApplyTLSConfiguration builds the shared transport from one tls block. It is what LoadFromConfiguration calls, split out so a test or a program without the configuration manager can install a block directly.

func HTTPClient

func HTTPClient(ctx context.Context, method string, url string, headers map[string]string, body any) (request *http.Request, response *http.Response, err error)

func LoadFromConfiguration

func LoadFromConfiguration(configurationNameId string) (err error)

LoadFromConfiguration reads the named configuration's "tls" block and builds the shared transport. A configuration with no tls block is not an error and changes nothing; a tls block with anything wrong in it is fatal, as it is for the server side and for the same reason.

func LogHandshakeFailure

func LogHandshakeFailure(l *log.DXLog, url string, err error)

LogHandshakeFailure logs what a failed outbound dial most likely means when TLS is configured: a wrong CA, a clock, a name, a refusal by the far side. The error itself is returned to the caller unchanged by every function that calls this; the classification is a log line beside it, so nothing a caller matches on has moved. l may be nil, in which case the package log is used.

func NewHTTPClient

func NewHTTPClient(timeout time.Duration) *http.Client

NewHTTPClient is the http.Client every outbound call in dxlib should use: the shared transport and the given timeout, zero meaning none.

func TLSClientConfig

func TLSClientConfig() *tls.Config

TLSClientConfig is the shared client tls.Config, or nil when none is configured, for a dialer that is not an http.Transport (gorilla/websocket).

func Transport

func Transport() http.RoundTripper

Transport is the shared outbound transport, or nil when none is configured. nil is a valid http.Client.Transport meaning DefaultTransport.

Types

type HTTPHeader

type HTTPHeader = map[string]string

type HTTPResponse

type HTTPResponse struct {
	StatusCode int
	Body       []byte
	Headers    map[string][]string
}

func HTTPClientReadAll

func HTTPClientReadAll(ctx context.Context, method string, url string, headers map[string]string, body any) (request *http.Request, response *HTTPResponse, err error)

func (*HTTPResponse) BodyAsJSON

func (hr *HTTPResponse) BodyAsJSON() (map[string]any, error)

func (*HTTPResponse) BodyAsString

func (hr *HTTPResponse) BodyAsString() string

Jump to

Keyboard shortcuts

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