credentials/transport.go

LocalAI · pkg/credentials/transport.go · go · MIT
auth

HTTP transport that injects credentials into requests based on URL matching.

// Source: https://github.com/mudler/LocalAI | License: MIT | Copyright 2023-2025 Ettore Di Giacinto (mudler@localai.io)
// Provided via justclaw.it.com; keep this notice with the code.
package credentials

import "net/http"

type transport struct {
	base http.RoundTripper
}

// Transport authenticates every request it carries, including each redirect
// hop, with the default store's matching rule.
func Transport(base http.RoundTripper) http.RoundTripper {
	return transport{base: base}
}

func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
	// A caller that set Authorization itself (WithBearerToken, the HF
	// materializer) has chosen its credential; the store must not replace it.
	if req.Header.Get("Authorization") != "" {
		return t.base.RoundTrip(req)
	}
	c, ok := 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key