Documentation
¶
Index ¶
- Variables
- func ApplyTLSConfiguration(tlsKV utils.JSON) error
- func HTTPClient(ctx context.Context, method string, url string, headers map[string]string, ...) (request *http.Request, response *http.Response, err error)
- func LoadFromConfiguration(configurationNameId string) (err error)
- func LogHandshakeFailure(l *log.DXLog, url string, err error)
- func NewHTTPClient(timeout time.Duration) *http.Client
- func TLSClientConfig() *tls.Config
- func Transport() http.RoundTripper
- type HTTPHeader
- type HTTPResponse
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 LoadFromConfiguration ¶
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 ¶
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 ¶
NewHTTPClient is the http.Client every outbound call in dxlib should use: the shared transport and the given timeout, zero meaning none.
func TLSClientConfig ¶
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 HTTPResponse ¶
func HTTPClientReadAll ¶
func (*HTTPResponse) BodyAsJSON ¶
func (hr *HTTPResponse) BodyAsJSON() (map[string]any, error)
func (*HTTPResponse) BodyAsString ¶
func (hr *HTTPResponse) BodyAsString() string