Forward CouchDB custom headers to fast fetch requests - #82
Open
nimula wants to merge 1 commit into
Open
Conversation
Fast Fetch built its own fetch headers from scratch and never read couchDB_CustomHeaders, unlike the normal replication path. Behind a reverse proxy that requires custom headers (e.g. Cloudflare Access Service Auth), this silently dropped every Fast Fetch request while normal replication kept working, and the resulting 401/403 responses were parsed as if they were changes-feed JSON. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Forward the configured CouchDB custom headers to Fast Fetch's native
fetchrequests.Context
Fast Fetch (
fetchChangesForInitialSyncinStreamingFetch.ts, called fromRebuilder.ts) builds its own request headers from scratch and never readscouchDB_CustomHeaders. This is inconsistent with the normal replication path, which parsescouchDB_CustomHeaderswithparseHeaderValues()and merges it into every PouchDB HTTP request via thefetchoverride inRemoteService.ts.Behind a reverse proxy that requires custom headers (for example, Cloudflare Access Service Auth with
CF-Access-Client-Id/CF-Access-Client-Secret), this means normal replication and the initial configuration checks succeed, but every Fast Fetch request is rejected by the proxy. The two request stages that were not checkingresponse.okcompounded the symptom: an HTML/JSON error page from the proxy was parsed as if it were changes-feed data, so the failure surfaced only as a generic retry loop with no HTTP status information.Related, but not the same issue:
RemoteService.ts.Changes
src/pouchdb/StreamingFetch.tscustomHeaders?: Record<string, string>parameter tofetchChangesForInitialSync.customHeadersinto the request headers, assigningAuthorizationlast so custom headers cannot override the CouchDB credential.throwIfNotOk()helper and call it before consuming the changes-summary and changes-stream responses, so a non-2xx response (401/403/etc.) raises a clear error naming the request stage and HTTP status instead of being parsed as JSON. The message intentionally omits header values.src/serviceModules/Rebuilder.tssettings.couchDB_CustomHeaderswith the existingparseHeaderValues()helper and pass it through tofetchChangesForInitialSync.Verification
Ran from this package (
livesync-commonlib) directly:npm run check:types— clean, no errors.npm test— 65 files / 1210 tests passed.Ran from the top-level plug-in repository (
obsidian-livesync) against the two changed files:npx vitest run --config vitest.config.unit.ts src/lib/src/pouchdb/StreamingFetch.unit.spec.ts src/lib/src/serviceModules/Rebuilder.unit.spec.ts— 25/25 passed, including 6 new cases covering header forwarding,Authorizationprecedence, and theresponse.okdiagnostics.npx eslint src/lib/src/pouchdb/StreamingFetch.ts src/lib/src/serviceModules/Rebuilder.ts— 0 errors.Note: the top-level plug-in repository's own
tsc --noEmitandnpm run buildare currently failing against this branch for reasons unrelated to this change — the plug-in repository'ssrc/libpin is ~40 commits behind this package'smain, and this package'smainhas already removed the globaleventHubexport and other APIs the plug-in repository has not yet migrated to. That gap is pre-existing and reproduces identically on a clean checkout ofmainwith this branch's four files stashed out, so it is not caused by this change.