Help us shape the future of Go! Take the 2026 Go Developer Survey

clientaddr

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package clientaddr decides which address a request came from, for the audit log (R-379, R-380), and carries it on the request's context to the audit writer.

A leaf: the API, the proxy and the audit writer all import it, and it imports nothing of Pando's.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func With

func With(ctx context.Context, req Request) context.Context

With returns ctx carrying req.

Types

type Request

type Request struct {
	SourceIP  string
	PeerIP    string
	UserAgent string
}

Request is what the audit log records about where a request came from.

func From

func From(ctx context.Context) (Request, bool)

From returns the request ctx carries, if any. A system process's context carries none, and its audit events record no source.

type Trusted

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

Trusted is the set of proxies whose X-Forwarded-For is believed. The zero value trusts nobody, which records the connecting peer — what Pando did before issue #129.

func Parse

func Parse(list string) (Trusted, error)

Parse reads a comma- or space-separated list of addresses and CIDRs. A bare address is a single host. An empty list trusts nobody.

func (Trusted) Empty

func (t Trusted) Empty() bool

Empty reports whether no proxy is trusted.

func (Trusted) Middleware

func (t Trusted) Middleware(next http.Handler) http.Handler

Middleware records each request's addresses on its context.

func (Trusted) Of

func (t Trusted) Of(r *http.Request) Request

Of describes a request, as t resolves it.

func (Trusted) Resolve

func (t Trusted) Resolve(r *http.Request) (source, peer string)

Resolve returns the client's address and the connecting peer's.

The peer is RemoteAddr's host. When the peer is trusted, X-Forwarded-For is read from the right and the first address that is not itself trusted is the client: the left of the header is whatever the client sent, and each trusted hop appends on the right. A hop that cannot be read ends the chain, and a chain of only trusted hops ends at its left-most.

Jump to

Keyboard shortcuts

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