httputil

package
v2.7.4 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = http.DefaultClient

DefaultClient stores original http.DefaultClient.

View Source
var DefaultTransport = http.DefaultTransport

DefaultTransport stores original http.DefaultTransport.

Functions

This section is empty.

Types

type HTTPClientBuilder

type HTTPClientBuilder struct {
	// contains filtered or unexported fields
}

HTTPClientBuilder builds http client with mocks (if necessary) and timeout. Example:

// Build HTTP client with timeout = 10 sec, without SSL certificates verification and with mocked google.com
client, err := NewHTTPClientBuilder().
	SetTimeout(10).
	SetMockAddress("api_mock:3004").
	AddMockedDomain("google.com").
	SetSSLVerification(false).
	Build()

if err != nil {
	fmt.Print(err)
}

// Actual response will be returned from "api_mock:3004" (it should provide any ssl certificate)
if resp, err := client.Get("https://google.com"); err == nil {
	if data, err := ioutil.ReadAll(resp.Body); err == nil {
		fmt.Printf("Data: %s", string(data))
	} else {
		fmt.Print(err)
	}
} else {
	fmt.Print(err)
}

func NewHTTPClientBuilder

func NewHTTPClientBuilder() *HTTPClientBuilder

NewHTTPClientBuilder returns HTTPClientBuilder with default values.

func (*HTTPClientBuilder) AddMockedDomain

func (b *HTTPClientBuilder) AddMockedDomain(domain string) *HTTPClientBuilder

AddMockedDomain adds new mocked domain.

func (*HTTPClientBuilder) Build

func (b *HTTPClientBuilder) Build(replaceDefault ...bool) (*http.Client, error)

Build builds client, pass true to replace http.DefaultClient with generated one.

func (*HTTPClientBuilder) FromConfig

FromConfig fulfills mock configuration from HTTPClientConfig.

func (*HTTPClientBuilder) ReplaceDefault

func (b *HTTPClientBuilder) ReplaceDefault() *HTTPClientBuilder

ReplaceDefault replaces default client and transport with generated ones.

func (*HTTPClientBuilder) RestoreDefault

func (b *HTTPClientBuilder) RestoreDefault() *HTTPClientBuilder

RestoreDefault restores default client and transport after replacement.

func (*HTTPClientBuilder) SetCertPool

func (b *HTTPClientBuilder) SetCertPool(pool *x509.CertPool) *HTTPClientBuilder

SetCertPool sets provided TLS certificates pool into the client.

func (*HTTPClientBuilder) SetLogging

func (b *HTTPClientBuilder) SetLogging(flag bool) *HTTPClientBuilder

SetLogging enables or disables logging in mocks.

func (*HTTPClientBuilder) SetMockAddress

func (b *HTTPClientBuilder) SetMockAddress(address string) *HTTPClientBuilder

SetMockAddress sets mock address.

func (*HTTPClientBuilder) SetMockedDomains

func (b *HTTPClientBuilder) SetMockedDomains(domains []string) *HTTPClientBuilder

SetMockedDomains sets mocked domains from slice.

func (*HTTPClientBuilder) SetSSLVerification

func (b *HTTPClientBuilder) SetSSLVerification(enabled bool) *HTTPClientBuilder

SetSSLVerification enables or disables SSL certificates verification in client.

func (*HTTPClientBuilder) SetTimeout

func (b *HTTPClientBuilder) SetTimeout(seconds time.Duration) *HTTPClientBuilder

SetTimeout sets timeout for http client.

func (*HTTPClientBuilder) UseTLS10

func (b *HTTPClientBuilder) UseTLS10() *HTTPClientBuilder

UseTLS10 restores TLS 1.0 as a minimal supported TLS version.

func (*HTTPClientBuilder) WithLogger

func (b *HTTPClientBuilder) WithLogger(logger logger.Logger) *HTTPClientBuilder

WithLogger sets provided logger into HTTPClientBuilder.

Jump to

Keyboard shortcuts

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