providerproxy

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package providerproxy is a record/replay HTTP proxy for the metadata providers Audiobookshelf calls out to.

abs-mcp never talks to Audible, Audnexus or iTunes itself: it asks Audiobookshelf to, and Audiobookshelf (a Node app) makes those calls. That puts them out of reach of anything that hooks Go's http.RoundTripper, so go-vcr and friends cannot see them. The only layer that can is a proxy in front of the container.

Audiobookshelf uses axios, which honours HTTPS_PROXY, so pointing it here plus NODE_TLS_REJECT_UNAUTHORIZED=0 (safe: the container is a throwaway) routes every provider call through this process. In record mode the real providers are called once and the responses are written to cassettes; in replay mode - the default, and what CI uses - they are served from disk and no network is touched.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Drift

type Drift struct {
	Key           string
	StatusWas     int
	StatusIs      int
	FieldsAdded   []string
	FieldsRemoved []string
}

Drift is one recorded interaction whose live response no longer has the shape the cassette captured.

Only the shape is compared, never the values: which book Audible ranks first this week is none of our business, but a field appearing, vanishing or changing type is exactly what breaks decoding. Every client bug this suite has found - the providers wrapper, the bookmarks wrapper, the batch update payload - was a shape change of this kind.

func (Drift) String

func (d Drift) String() string

type Mode

type Mode int

Mode selects whether the proxy calls the real providers.

const (
	// Replay serves from the cassettes and never reaches the network. A
	// request with no recording is a loud failure, not an empty response.
	Replay Mode = iota
	// Record calls the real provider and writes what comes back.
	Record
	// Verify calls the real provider and compares the shape of what comes
	// back against the cassette, without writing. The recorded response is
	// still what gets served, so a test outcome never depends on what a
	// provider happened to return today - drift is reported separately.
	Verify
)

type Options

type Options struct {
	// Mode defaults to Replay.
	Mode Mode
	// CassetteDir holds one JSON file per provider host.
	CassetteDir string
	// Addr to listen on. Must be reachable from the container, so bind all
	// interfaces (e.g. "0.0.0.0:18080").
	Addr string
	// Logger receives replay misses and record notices; defaults to stderr.
	Logger *log.Logger
}

Options configure a Proxy.

type Proxy

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

Proxy is a MITM HTTP proxy backed by cassettes.

func New

func New(opts Options) (*Proxy, error)

New starts a proxy and returns it. Close stops it and, in Record mode, flushes the cassettes.

func (*Proxy) Addr

func (p *Proxy) Addr() string

Addr is the address the proxy is listening on.

func (*Proxy) Close

func (p *Proxy) Close() error

Close stops the proxy, writing any newly recorded cassettes.

func (*Proxy) Drifts

func (p *Proxy) Drifts() []Drift

Drifts returns the shape changes seen so far, in a stable order. Empty in any mode but Verify.

func (*Proxy) Misses

func (p *Proxy) Misses() []string

Misses returns the requests that had no recording, so a replay run can fail with the list rather than leaving tests to pass on empty responses.

func (*Proxy) Port

func (p *Proxy) Port() int

Port is the port the proxy is listening on.

Jump to

Keyboard shortcuts

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