http

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewHTTPPool = func(
	minSize, maxSize int,
	idleTimeout time.Duration,
	config *configv1.UpstreamServiceConfig,
) (pool.Pool[*client.HTTPClientWrapper], error) {
	factory := func(_ context.Context) (*client.HTTPClientWrapper, error) {
		tlsConfig := &tls.Config{
			MinVersion:         tls.VersionTLS12,
			InsecureSkipVerify: config.GetHttpService().GetTlsConfig().GetInsecureSkipVerify(),
		}

		if mtlsConfig := config.GetUpstreamAuthentication().GetMtls(); mtlsConfig != nil {
			cert, err := tls.LoadX509KeyPair(mtlsConfig.GetClientCertPath(), mtlsConfig.GetClientKeyPath())
			if err != nil {
				return nil, err
			}
			tlsConfig.Certificates = []tls.Certificate{cert}

			caCert, err := os.ReadFile(mtlsConfig.GetCaCertPath())
			if err != nil {
				return nil, err
			}
			caCertPool := x509.NewCertPool()
			caCertPool.AppendCertsFromPEM(caCert)
			tlsConfig.RootCAs = caCertPool
		}

		return client.NewHTTPClientWrapper(
			&http.Client{
				Transport: otelhttp.NewTransport(&http.Transport{
					TLSClientConfig: tlsConfig,
					DialContext: (&net.Dialer{
						Timeout: 30 * time.Second,
					}).DialContext,
				}),
			},
			config,
		), nil
	}
	return pool.New(factory, minSize, maxSize, idleTimeout, false)
}

NewHTTPPool creates a new connection pool for HTTP clients. It is defined as a variable to allow for easy mocking in tests.

minSize is the initial number of clients to create. maxSize is the maximum number of clients the pool can hold. idleTimeout is the duration after which an idle client may be closed (not currently implemented). healthCheck is the configuration for the health check. It returns a new HTTP client pool or an error if the pool cannot be created.

Functions

func NewUpstream

func NewUpstream(poolManager *pool.Manager) upstream.Upstream

NewUpstream creates a new instance of Upstream.

Parameters:

  • poolManager: The connection pool manager to be used for managing HTTP connections.

Returns:

  • An implementation of the upstream.Upstream interface.

Types

type Upstream

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

Upstream implements the upstream.Upstream interface for services that are exposed via standard HTTP endpoints. It handles the registration of tools defined in the service configuration.

func (*Upstream) Register

func (u *Upstream) Register(
	ctx context.Context,
	serviceConfig *configv1.UpstreamServiceConfig,
	toolManager tool.ManagerInterface,
	promptManager prompt.ManagerInterface,
	resourceManager resource.ManagerInterface,
	isReload bool,
) (string, []*configv1.ToolDefinition, []*configv1.ResourceDefinition, error)

Register processes the configuration for an HTTP service, creates a connection pool for it, and then creates and registers tools for each call definition specified in the configuration.

func (*Upstream) Shutdown

func (u *Upstream) Shutdown(_ context.Context) error

Shutdown gracefully terminates the HTTP upstream service by shutting down the associated connection pool.

Jump to

Keyboard shortcuts

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