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 ¶
const RecordEnv = "ABS_TEST_RECORD"
RecordEnv is the variable the suites record with: set, they run the proxy in Record mode, and set to "all" (as make record does) New makes that a Rerecord.
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.
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 for a request no cassette holds and // writes what comes back; a request already recorded is served from its // recording, so recording a new test's lookups (ABS_TEST_RECORD=1) leaves // every other recording as it was. 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 // Rerecord is Record refreshing what is recorded as well (make record): // the first time the proxy sees a request it calls the real provider and // the answer replaces the recording, and the same request again in that // run is served the fresh answer without another call. Rerecord )
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 ¶
New starts a proxy and returns it. Close stops it and, when it records, flushes the cassettes.
func (*Proxy) Drifts ¶
Drifts returns the shape changes seen so far, in a stable order. Empty in any mode but Verify.
func (*Proxy) Misses ¶
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) Serve ¶ added in v0.5.0
Serve answers every request for host with h instead of a cassette, until the returned func is called. It is for the hosts a test plays itself - a podcast feed whose episodes it adds as it goes - which have no provider to record: nothing for such a host is recorded, replayed or counted as a miss. The host needs no DNS: the container sends the whole url to the proxy.