AudioProxy.Plugs.ParseOptions (audio_proxy v0.7.0)

Copy Markdown View Source

Splits the verified rest-of-path into its options half and source half, and parses the options (API doc §1, §3).

The source half begins at the first plain or enc segment — the two source encodings AudioProxy.Source knows, mirrored here because the options grammar cannot delimit itself: a bare segment like plain is not a valid key:value option, so it marks where options end. An option value can never collide (segments are matched whole, and every option segment carries a :), and a marker later in the source is safe because only the first one splits.

On success the parsed %AudioProxy.Options{} lands in assigns.options and the source half — raw, still percent-escaped, exactly the bytes the signature covered — in assigns.source_string for AudioProxy.Plugs.ResolveSource. On failure the plug halts through AudioProxy.ErrorJSON: an options error as the 422 naming its segment, and a path with no source marker as the generic 404 (nothing servable is named).

info, the one segment that is not an option

GET /{sig}/info/{source} (§2) puts a bare info where the options go, and it is not an option: it names a different endpoint over the same source. So it is recognized here, before the options grammar sees it, and it is exclusive — §2 gives the info endpoint no processing options, and the rule is one line rather than a per-option exception list: info alone is an info request, info with anything else is a 422 naming the segment it cannot be combined with.

An info request assigns :action as :info and deliberately assigns no :options — there is no variant being described, and a materialized default %Options{} would put an opts=f:mp3 on the log line of a request that asked for no such thing. AudioProxy.Plugs.Action reads :action to pick the action; every other request leaves it :render.

Bare info is unambiguous as a marker for the same reason plain and enc are: every real option segment carries a :, so no option value can spell it, and only the options half is scanned.

Expects AudioProxy.Plugs.VerifySignature to have run: rest_of_path must be the verified raw path bytes, never conn.path_info — the source parser decodes exactly once, and handing it pre-decoded segments would decode twice.