transport

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package transport implements the HTTP layer the helper protocol speaks against: a Proxy that talks to one or more Entire data-plane replicas, applies failover on connection errors and 5xx responses, and bridges the warm/cold paths driven by X-Entire-Replicas.

The Proxy is decoupled from authentication via a SetAuthFunc — the caller (cmd/entire's runRemoteHelper) wires the scoped-token mint in there. checkRedirect enforces the same-cluster Authorization carry rule so credentials never leak across hosts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPErrorMessage

func HTTPErrorMessage(statusCode int, serverMsg, baseURL string) error

HTTPErrorMessage returns a user-friendly error for non-200 HTTP responses. Exposed so handlers outside the transport package can produce the same shape.

Types

type Config

type Config struct {
	Nodes        replicas.NodeConfig
	Path         string
	SkipTLS      bool
	SetAuth      SetAuthFunc
	OnNodeFailed func(failedNode string)
}

Config bundles the inputs needed to build a Proxy. Path is the URL path on each node (e.g. "/et/project/repo") and is appended to the node base for every request.

type Proxy

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

Proxy is the HTTP transport the helper protocol uses to talk to the data plane. Methods are not safe for concurrent use — Git's helper protocol is strictly serial.

func New

func New(cfg Config) *Proxy

New builds a Proxy from the given configuration. The HTTP client is constructed here so that its CheckRedirect can reference the proxy (otherwise the cross-host Authorization-stripping policy would need duplicate state).

func (*Proxy) ErrorBaseURL

func (p *Proxy) ErrorBaseURL() string

ErrorBaseURL returns a URL string suitable for embedding in error messages, guarding against empty node lists.

func (*Proxy) InfoRefs

func (p *Proxy) InfoRefs(ctx context.Context, service string) (io.ReadCloser, error)

InfoRefs fetches the ref advertisement from the server. This is also the discovery entry point: the response's X-Entire-Replicas header refreshes the proxy's cached replica set, and every subsequent request in this invocation hits one of those replicas directly.

Warm path: when the cache has replicas, they're tried with failover. If every cached replica fails we fall back to the cold path rather than surfacing the error — the cached set may be entirely stale (cluster resized, replicas moved) and the entry domain's LB will still route us to a live node.

Cold path: probe the entry domain without auto-following 3xx. If it returns 307 + X-Entire-Replicas we adopt those replicas as the working set and run the warm-path failover instead of letting Go's HTTP client dial the redirect target — that matters when the redirect target's DNS or TCP is broken: failover rolls to the next replica instead of returning the dial error. When the redirect carries no replica header we fall back to following the redirect once. A direct 2xx is handled in place.

func (*Proxy) InfoRefsV2

func (p *Proxy) InfoRefsV2(ctx context.Context) (io.ReadCloser, error)

InfoRefsV2 is InfoRefs with Git-Protocol: version=2 added — same replica-failover / cold-path / discovery logic, but the server's v2 capability advertisement is what gets returned instead of the v0/v1 ref list.

func (*Proxy) ServiceRPC

func (p *Proxy) ServiceRPC(ctx context.Context, service string, body io.ReadSeeker, extraHeaders ...func(*http.Request)) (io.ReadCloser, error)

ServiceRPC sends data to a Git service endpoint and returns the response. The extraHeaders callbacks are invoked on each request to set additional headers (e.g. Git-Protocol, X-Entire-Push-Size).

type SetAuthFunc

type SetAuthFunc func(*http.Request) error

SetAuthFunc attaches authentication headers to an outbound request. Errors are surfaced verbatim — they short-circuit failover because they originate at the auth provider, not the data-plane node.

Jump to

Keyboard shortcuts

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